You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connect4/Model/Tests/ModelTests/EmptyBoardTests.swift

67 lines
1.7 KiB

1 month ago
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])
let result = board.countPieces()
XCTAssertEqual(result.a, 0)
XCTAssertEqual(result.b, 0)
1 month ago
}
func testSetGet() throws {
board[1, 1] = Piece.PlayerA;
1 month ago
XCTAssertEqual(board[1, 1], .PlayerA)
1 month ago
}
func testCounts() throws {
board[1, 2] = .PlayerB
1 month ago
let counts = board.countPieces()
XCTAssertEqual(counts.a, 0)
XCTAssertEqual(counts.b, 1)
1 month ago
}
func testInsertTopNoPush() {
XCTAssert(board.insert(piece: .PlayerA, side: .Top, offset: 2))
XCTAssertEqual(board[2, 0], .PlayerA)
1 month ago
}
func testInsertBottomNoPush() {
XCTAssert(board.insert(piece: .PlayerB, side: .Bottom, offset: 2))
XCTAssertEqual(board[2, board.rows - 1], .PlayerB)
1 month ago
}
func testInsertLeftNoPush() {
XCTAssert(board.insert(piece: .PlayerA, side: .Left, offset: 2))
XCTAssertEqual(board[0, 2], .PlayerA)
1 month ago
}
func testInsertRightNoPush() {
XCTAssert(board.insert(piece: .PlayerB, side: .Right, offset: 2))
XCTAssertEqual(board[board.columns - 1, 2], .PlayerB)
1 month ago
}
}