Change pieces names

Boards
Mathieu GROUSSEAU 5 months ago
parent 9d200b7b79
commit 164a0528f0

@ -39,9 +39,9 @@ public struct Board {
for column in grid { for column in grid {
for piece in column { for piece in column {
switch piece { switch piece {
case .Player1: case .PlayerA:
a += 1 a += 1
case .Player2: case .PlayerB:
b += 1 b += 1
case nil: case nil:
break break

@ -1,3 +1,3 @@
public enum Piece { public enum Piece {
case Player1, Player2 case PlayerA, PlayerB
} }

@ -31,13 +31,13 @@ final class EmptyBoardTests: XCTestCase {
} }
func testSetGet() throws { func testSetGet() throws {
board[1, 1] = Piece.Player1; board[1, 1] = Piece.PlayerA;
XCTAssertEqual(board[1, 1], .Player1) XCTAssertEqual(board[1, 1], .PlayerA)
} }
func testCounts() throws { func testCounts() throws {
board[1, 2] = .Player2 board[1, 2] = .PlayerB
let counts = board.countPieces() let counts = board.countPieces()
XCTAssertEqual(counts.a, 0) XCTAssertEqual(counts.a, 0)
@ -45,22 +45,22 @@ final class EmptyBoardTests: XCTestCase {
} }
func testInsertTopNoPush() { func testInsertTopNoPush() {
XCTAssert(board.insert(piece: .Player1, side: .Top, offset: 2)) XCTAssert(board.insert(piece: .PlayerA, side: .Top, offset: 2))
XCTAssertEqual(board[2, 0], .Player1) XCTAssertEqual(board[2, 0], .PlayerA)
} }
func testInsertBottomNoPush() { func testInsertBottomNoPush() {
XCTAssert(board.insert(piece: .Player2, side: .Bottom, offset: 2)) XCTAssert(board.insert(piece: .PlayerB, side: .Bottom, offset: 2))
XCTAssertEqual(board[2, board.rows - 1], .Player2) XCTAssertEqual(board[2, board.rows - 1], .PlayerB)
} }
func testInsertLeftNoPush() { func testInsertLeftNoPush() {
XCTAssert(board.insert(piece: .Player1, side: .Left, offset: 2)) XCTAssert(board.insert(piece: .PlayerA, side: .Left, offset: 2))
XCTAssertEqual(board[0, 2], .Player1) XCTAssertEqual(board[0, 2], .PlayerA)
} }
func testInsertRightNoPush() { func testInsertRightNoPush() {
XCTAssert(board.insert(piece: .Player2, side: .Right, offset: 2)) XCTAssert(board.insert(piece: .PlayerB, side: .Right, offset: 2))
XCTAssertEqual(board[board.columns - 1, 2], .Player2) XCTAssertEqual(board[board.columns - 1, 2], .PlayerB)
} }
} }

@ -15,9 +15,9 @@ final class FilledBoardTests: XCTestCase {
for row in 0..<board.rows { for row in 0..<board.rows {
for col in 0..<board.columns { for col in 0..<board.columns {
board[col, row] = if (row & 1) == 1 { board[col, row] = if (row & 1) == 1 {
.Player1 .PlayerA
} else { } else {
.Player2 .PlayerB
} }
} }
} }
@ -27,25 +27,25 @@ final class FilledBoardTests: XCTestCase {
func testInsertFailTopNoPush() { func testInsertFailTopNoPush() {
let before = board[2, 0] let before = board[2, 0]
XCTAssertFalse(board.insert(piece: .Player1, side: .Top, offset: 2)) XCTAssertFalse(board.insert(piece: .PlayerA, side: .Top, offset: 2))
XCTAssertEqual(before, board[2, 0]) XCTAssertEqual(before, board[2, 0])
} }
func testInsertFailBottomNoPush() { func testInsertFailBottomNoPush() {
let before = board[2, board.rows - 1] let before = board[2, board.rows - 1]
XCTAssertFalse(board.insert(piece: .Player2, side: .Bottom, offset: 2)) XCTAssertFalse(board.insert(piece: .PlayerB, side: .Bottom, offset: 2))
XCTAssertEqual(before, board[2, board.rows - 1]) XCTAssertEqual(before, board[2, board.rows - 1])
} }
func testInsertFailLeftNoPush() { func testInsertFailLeftNoPush() {
let before = board[2, 0] let before = board[2, 0]
XCTAssertFalse(board.insert(piece: .Player1, side: .Left, offset: 2)) XCTAssertFalse(board.insert(piece: .PlayerA, side: .Left, offset: 2))
XCTAssertEqual(before, board[0, 2]) XCTAssertEqual(before, board[0, 2])
} }
func testInsertFailRightNoPush() { func testInsertFailRightNoPush() {
let before = board[board.columns - 1, 2] let before = board[board.columns - 1, 2]
XCTAssertFalse(board.insert(piece: .Player2, side: .Right, offset: 2)) XCTAssertFalse(board.insert(piece: .PlayerB, side: .Right, offset: 2))
XCTAssertEqual(before, board[board.columns - 1, 2]) XCTAssertEqual(before, board[board.columns - 1, 2])
} }