Created
May 5, 2018 21:52
-
-
Save wingchi/b8f20afb85de012f4ed74e880e1c5978 to your computer and use it in GitHub Desktop.
Unit Tests for Grid Cell sizing 1-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GridViewModelTests: XCTestCase { | |
let testFrame = CGRect(x: 0, y: 0, width: 72, height: 130) | |
let expectedFullWidth: CGFloat = 72 // 72 | |
let expectedHeight = (130 / 5) - 2 * GridViewModel.itemMargin //10 | |
func testOneItemCellSize() { | |
let expectedCellSize = CGSize(width: expectedFullWidth, height: expectedHeight) | |
let viewModel = GridViewModel() | |
viewModel.data = [1] | |
let row = 0 | |
let testIndexPath = IndexPath(row: row, section: 0) | |
let cellSize = viewModel.cellSize(for: testFrame, at: testIndexPath) | |
XCTAssertEqual(cellSize, expectedCellSize) | |
} | |
// ... tests two through four | |
func testFiveItemCellSize() { | |
let expectedCellSizes = [ | |
CGSize(width: expectedFullWidth, height: expectedHeight), | |
CGSize(width: expectedFullWidth, height: expectedHeight), | |
CGSize(width: expectedFullWidth, height: expectedHeight), | |
CGSize(width: expectedFullWidth, height: expectedHeight), | |
CGSize(width: expectedFullWidth, height: expectedHeight) | |
] | |
let viewModel = GridViewModel() | |
viewModel.data = [1, 2, 3, 4, 5] | |
for row in 0...(viewModel.data.count - 1) { | |
let testIndexPath = IndexPath(row: row, section: 0) | |
let cellSize = viewModel.cellSize(for: testFrame, at: testIndexPath) | |
XCTAssertEqual(cellSize, expectedCellSizes[row]) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment