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.
67 lines
1.8 KiB
67 lines
1.8 KiB
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)
|
|
}
|
|
}
|