From 279629a556c01d474ea17d444f2e225085d9d253 Mon Sep 17 00:00:00 2001 From: Alexis Drai Date: Tue, 24 Jan 2023 15:43:13 +0100 Subject: [PATCH] :white_check_mark: Board (pt.3) --- Connect4/connect4_lib/Sources/connect4_lib/Board.swift | 3 +++ .../connect4_lib/Tests/connect4_libTests/BoardTest.swift | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Connect4/connect4_lib/Sources/connect4_lib/Board.swift b/Connect4/connect4_lib/Sources/connect4_lib/Board.swift index 76a1023..a81870a 100644 --- a/Connect4/connect4_lib/Sources/connect4_lib/Board.swift +++ b/Connect4/connect4_lib/Sources/connect4_lib/Board.swift @@ -28,6 +28,9 @@ public struct Board : CustomStringConvertible { for tile in row { if tile != nil { nbFree -= 1 + if (tile != 1 && tile != 2) { + return nil + } } } } diff --git a/Connect4/connect4_lib/Tests/connect4_libTests/BoardTest.swift b/Connect4/connect4_lib/Tests/connect4_libTests/BoardTest.swift index 9ba40d6..0420a5c 100644 --- a/Connect4/connect4_lib/Tests/connect4_libTests/BoardTest.swift +++ b/Connect4/connect4_lib/Tests/connect4_libTests/BoardTest.swift @@ -39,11 +39,12 @@ final class BoardTest: XCTestCase { XCTAssertEqual(orig.count, board?.nbRows) } - expect(withGrid: [[0, 1, 2], [0, 0, 0], [0, 0, 0]], shouldNotBeNil: true) + expect(withGrid: [[nil, nil, nil], [nil, nil, nil], [nil, 1, 2]], shouldNotBeNil: true) expect(withGrid: [], shouldNotBeNil: false) expect(withGrid: [[], []], shouldNotBeNil: false) - expect(withGrid: [[0, 1], [0, 0]], shouldNotBeNil: false) - expect(withGrid: [[0, 1, 2], [0, 0, 0, 0]], shouldNotBeNil: false) + expect(withGrid: [[nil, nil], [nil, 1]], shouldNotBeNil: false) + expect(withGrid: [[nil, nil, nil], [nil, nil, 1, 2]], shouldNotBeNil: false) + expect(withGrid: [[nil, nil, nil], [nil, nil, nil], [nil, 1, 3]], shouldNotBeNil: false) } func testIsFull() throws {