parent
55cedeb7b0
commit
b2e799496a
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -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..<board.rows {
|
||||||
|
for col in 0..<board.columns {
|
||||||
|
board[col, row] = if (row & 1) == 1 {
|
||||||
|
.Player1
|
||||||
|
} else {
|
||||||
|
.Player2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.board = board
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInsertFailTopNoPush() {
|
||||||
|
let before = board[2, 0]
|
||||||
|
XCTAssertFalse(board.insert(piece: .Player1, side: .Top, offset: 2))
|
||||||
|
XCTAssertEqual(before, board[2, 0])
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInsertFailBottomNoPush() {
|
||||||
|
let before = board[2, board.rows - 1]
|
||||||
|
XCTAssertFalse(board.insert(piece: .Player2, side: .Bottom, offset: 2))
|
||||||
|
XCTAssertEqual(before, board[2, board.rows - 1])
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInsertFailLeftNoPush() {
|
||||||
|
let before = board[2, 0]
|
||||||
|
XCTAssertFalse(board.insert(piece: .Player1, side: .Left, offset: 2))
|
||||||
|
XCTAssertEqual(before, board[0, 2])
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInsertFailRightNoPush() {
|
||||||
|
let before = board[board.columns - 1, 2]
|
||||||
|
XCTAssertFalse(board.insert(piece: .Player2, side: .Right, offset: 2))
|
||||||
|
XCTAssertEqual(before, board[board.columns - 1, 2])
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Test shifting
|
||||||
|
}
|
@ -1,11 +0,0 @@
|
|||||||
import XCTest
|
|
||||||
@testable import Model
|
|
||||||
|
|
||||||
final class ModelTests: XCTestCase {
|
|
||||||
func testExample() throws {
|
|
||||||
// This is an example of a functional test case.
|
|
||||||
// Use XCTAssert and related functions to verify your tests produce the correct
|
|
||||||
// results.
|
|
||||||
XCTAssertEqual(Model().text, "Hello, World!")
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue