diff --git a/Model/Tests/ModelTests/EmptyBoardTests.swift b/Model/Tests/ModelTests/EmptyBoardTests.swift new file mode 100644 index 0000000..05d8ede --- /dev/null +++ b/Model/Tests/ModelTests/EmptyBoardTests.swift @@ -0,0 +1,66 @@ +import XCTest +@testable import Model + +final class EmptyBoardTests: XCTestCase { + private var board: Board! + + override func setUp() { + super.setUp() + + guard let board = Board(columns: 5, rows: 6) else { + XCTFail() + return + } + + self.board = board + } + + func testWidth() throws { + XCTAssertEqual(board.columns, 5) + } + + func testHeight() throws { + XCTAssertEqual(board.rows, 6) + } + + func testEmptyByDefault() throws { + XCTAssertNil(board[1, 1]) + XCTAssertEqual(board.countPieces(), 0) + XCTAssertEqual(board.countPieces(of_type: .Player1), 0) + XCTAssertEqual(board.countPieces(of_type: .Player2), 0) + } + + func testSetGet() throws { + board[1, 1] = Piece.Player1; + + XCTAssertEqual(board[1, 1], .Player1) + } + + func testCounts() throws { + board[1, 2] = .Player2 + + XCTAssertEqual(board.countPieces(), 1) + XCTAssertEqual(board.countPieces(of_type: .Player1), 0) + XCTAssertEqual(board.countPieces(of_type: .Player2), 1) + } + + func testInsertTopNoPush() { + XCTAssert(board.insert(piece: .Player1, side: .Top, offset: 2)) + XCTAssertEqual(board[2, 0], .Player1) + } + + func testInsertBottomNoPush() { + XCTAssert(board.insert(piece: .Player2, side: .Bottom, offset: 2)) + XCTAssertEqual(board[2, board.rows - 1], .Player2) + } + + func testInsertLeftNoPush() { + XCTAssert(board.insert(piece: .Player1, side: .Left, offset: 2)) + XCTAssertEqual(board[0, 2], .Player1) + } + + func testInsertRightNoPush() { + XCTAssert(board.insert(piece: .Player2, side: .Right, offset: 2)) + XCTAssertEqual(board[board.columns - 1, 2], .Player2) + } +} diff --git a/Model/Tests/ModelTests/FilledBoardTests.swift b/Model/Tests/ModelTests/FilledBoardTests.swift new file mode 100644 index 0000000..8c475f0 --- /dev/null +++ b/Model/Tests/ModelTests/FilledBoardTests.swift @@ -0,0 +1,53 @@ +import XCTest +@testable import Model + +final class FilledBoardTests: XCTestCase { + private var board: Board! + + override func setUp() { + super.setUp() + + guard var board = Board(columns: 5, rows: 6) else { + XCTFail() + return + } + + for row in 0..