|
|
@ -39,8 +39,81 @@ final class BasicDefaultNoDiagTest: XCTestCase {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func testIsGameOver() throws {
|
|
|
|
func testIsGameOver() throws {
|
|
|
|
func expect() {
|
|
|
|
func expect(byPlayer playerId: Int,
|
|
|
|
|
|
|
|
withGrid grid: [[Int?]],
|
|
|
|
|
|
|
|
shouldBeOver: Bool,
|
|
|
|
|
|
|
|
shouldHaveWinner: Bool,
|
|
|
|
|
|
|
|
victoryTilesShouldBe: [(Int, Int)]?) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let rules = BasicDefaultsNoDiag(withMinNbRows: 3, withMaxNbRows: 5, withMinNbCols: 3, withMaxNbCols: 5, withNbChipsToAlign: 3) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XCTAssertEqual(shouldBeOver, rules.isGameOver(byPlayer: playerId, onGrid: grid).isOver)
|
|
|
|
|
|
|
|
XCTAssertEqual(shouldHaveWinner, rules.isGameOver(byPlayer: playerId, onGrid: grid).hasWinner)
|
|
|
|
|
|
|
|
XCTAssertFalse(rules.isGameOver(byPlayer: playerId, onGrid: grid).hasWinner && !(rules.isGameOver(byPlayer: playerId, onGrid: grid).isOver))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if shouldHaveWinner {
|
|
|
|
|
|
|
|
XCTAssertTrue(rules.isGameOver(byPlayer: playerId, onGrid: grid).isOver)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let actualVictoryTiles = rules.isGameOver(byPlayer: playerId, onGrid: grid).victoryTiles
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XCTAssertNotNil(actualVictoryTiles)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for n in 0..<victoryTilesShouldBe!.count {
|
|
|
|
|
|
|
|
XCTAssertEqual(victoryTilesShouldBe![n].0, actualVictoryTiles![n].0)
|
|
|
|
|
|
|
|
XCTAssertEqual(victoryTilesShouldBe![n].1, actualVictoryTiles![n].1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(byPlayer: 1,
|
|
|
|
|
|
|
|
withGrid: [[nil, nil, nil],
|
|
|
|
|
|
|
|
[nil, nil, nil],
|
|
|
|
|
|
|
|
[nil, nil, nil]],
|
|
|
|
|
|
|
|
shouldBeOver: false,
|
|
|
|
|
|
|
|
shouldHaveWinner: false,
|
|
|
|
|
|
|
|
victoryTilesShouldBe: nil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(byPlayer: 2,
|
|
|
|
|
|
|
|
withGrid: [[nil, nil, nil],
|
|
|
|
|
|
|
|
[nil, nil, nil],
|
|
|
|
|
|
|
|
[2, nil, nil]],
|
|
|
|
|
|
|
|
shouldBeOver: false,
|
|
|
|
|
|
|
|
shouldHaveWinner: false,
|
|
|
|
|
|
|
|
victoryTilesShouldBe: nil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(byPlayer: 1,
|
|
|
|
|
|
|
|
withGrid: [[2, nil, nil],
|
|
|
|
|
|
|
|
[1, 1, 1],
|
|
|
|
|
|
|
|
[2, 2, 1]],
|
|
|
|
|
|
|
|
shouldBeOver: true,
|
|
|
|
|
|
|
|
shouldHaveWinner: true,
|
|
|
|
|
|
|
|
victoryTilesShouldBe: [(1, 0), (1, 1), (1, 2)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(byPlayer: 2,
|
|
|
|
|
|
|
|
withGrid: [[nil, nil, nil, nil, nil],
|
|
|
|
|
|
|
|
[nil, nil, nil, nil, nil],
|
|
|
|
|
|
|
|
[nil, nil, nil, nil, nil],
|
|
|
|
|
|
|
|
[nil, nil, nil, 1, nil],
|
|
|
|
|
|
|
|
[1, 1, 2, 2, 2]],
|
|
|
|
|
|
|
|
shouldBeOver: true,
|
|
|
|
|
|
|
|
shouldHaveWinner: true,
|
|
|
|
|
|
|
|
victoryTilesShouldBe: [(4, 2), (4, 3), (4, 4)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(byPlayer: 1,
|
|
|
|
|
|
|
|
withGrid: [[nil, nil, 1],
|
|
|
|
|
|
|
|
[nil, 2, 1],
|
|
|
|
|
|
|
|
[nil, 2, 1]],
|
|
|
|
|
|
|
|
shouldBeOver: true,
|
|
|
|
|
|
|
|
shouldHaveWinner: true,
|
|
|
|
|
|
|
|
victoryTilesShouldBe: [(0, 2), (1, 2), (2, 2)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(byPlayer: 1,
|
|
|
|
|
|
|
|
withGrid: [[1, 2, 1],
|
|
|
|
|
|
|
|
[1, 2, 1],
|
|
|
|
|
|
|
|
[2, 1, 2]],
|
|
|
|
|
|
|
|
shouldBeOver: true,
|
|
|
|
|
|
|
|
shouldHaveWinner: false,
|
|
|
|
|
|
|
|
victoryTilesShouldBe: nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|