diff --git a/Src/CLT/CLT/main.swift b/Src/CLT/CLT/main.swift index e80fd7e..de52867 100644 --- a/Src/CLT/CLT/main.swift +++ b/Src/CLT/CLT/main.swift @@ -35,7 +35,3 @@ if var board = Board(withGrid: [[1,2,1], [2,1,nil], [nil,nil,nil]]){ insertPiece(id: 1, column: 0, &board) insertPiece(id: 1, column: 0, &board) } - -var c = ClassicRules() -var b = c.createBoard() -print(b) diff --git a/Src/Model/Sources/Model/Board/Board.swift b/Src/Model/Sources/Model/Board/Board.swift index bcb083c..6c722fe 100644 --- a/Src/Model/Sources/Model/Board/Board.swift +++ b/Src/Model/Sources/Model/Board/Board.swift @@ -79,7 +79,7 @@ public struct Board : CustomStringConvertible { /// Verify if the board is full /// /// - Returns: True if the board is full else false - private func isFull() -> Bool{ + public func isFull() -> Bool{ for column in 0.. BoardResult { - for row in 0.. (Bool, Int, GameResult) { - (true, 8, .lose) - } - public static var nbRows: Int = 6 public static var nbColumns: Int = 7 public static var nbAlignedPieces: Int = 4 public static var nbTrials: Int = 3 - + public init() {} - - /// - public func createBoard() -> Board { - return Board(withNbRows: Self.nbRows, withNbColumns: Self.nbColumns)! - } + +// public func createBoard() -> Board { +// +// } +// +// public func isGameOver() -> (Bool, Int, GameResult) { +// <#code#> +// } +// +// public func getNextPlayer() -> Int { +// <#code#> +// } } diff --git a/Src/Model/Tests/ModelTests/Board/BoardTest.swift b/Src/Model/Tests/ModelTests/Board/BoardTest.swift deleted file mode 100644 index 43c4b5b..0000000 --- a/Src/Model/Tests/ModelTests/Board/BoardTest.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// BoardTest.swift -// -// -// Created by BREUIL Yohann on 19/01/2023. -// - -import XCTest -import Model - -final class BoardTest: XCTestCase { - func testInit() throws { - func expect(nbRows : Int, nbColumns : Int, notNil : Bool) { - let board = Board(withNbRows: nbRows, withNbColumns: nbColumns) - - if !notNil { - XCTAssertNil(board) - return - } - XCTAssertNotNil(board) - XCTAssertEqual(board?.nbRows, nbRows) - XCTAssertEqual(board?.nbColumns, nbColumns) - } - - expect(nbRows: 6, nbColumns: 7, notNil: true) - expect(nbRows: 0, nbColumns: 7, notNil: false) - expect(nbRows: 6, nbColumns: 0, notNil: false) - expect(nbRows: 0, nbColumns: 0, notNil: false) - } -} diff --git a/Src/Model/Tests/ModelTests/Board/BoardTests.swift b/Src/Model/Tests/ModelTests/Board/BoardTests.swift new file mode 100644 index 0000000..5f872ae --- /dev/null +++ b/Src/Model/Tests/ModelTests/Board/BoardTests.swift @@ -0,0 +1,79 @@ +import XCTest +import Model + +final class BoardTest: XCTestCase { + func testInitWithVaalues() throws { + func expect(nbRows : Int, nbColumns : Int, notNil : Bool) { + let board = Board(withNbRows: nbRows, withNbColumns: nbColumns) + + if !notNil { + XCTAssertNil(board) + return + } + XCTAssertNotNil(board) + XCTAssertEqual(board?.nbRows, nbRows) + XCTAssertEqual(board?.nbColumns, nbColumns) + } + + expect(nbRows: 6, nbColumns: 7, notNil: true) + expect(nbRows: 0, nbColumns: 7, notNil: false) + expect(nbRows: 6, nbColumns: 0, notNil: false) + expect(nbRows: 0, nbColumns: 0, notNil: false) + expect(nbRows: -2, nbColumns: 7, notNil: false) + expect(nbRows: 6, nbColumns: -2, notNil: false) + } + + func testInitWithGrid() { + func expect(grid : [[Int?]], notNil: Bool) { + let board = Board(withGrid: grid) + + if !notNil { + XCTAssertNil(board) + return + } + + XCTAssertNotNil(board) + XCTAssertEqual(board?.gridBoard, grid) + } + + expect(grid: [[1,2], [2,1], [2,1]], notNil: true) + expect(grid: [[1,2], [2,1], [nil,nil]], notNil: true) + expect(grid: [[nil,nil], [nil,nil], [nil,nil]], notNil: true) + expect(grid: [[1], [2,1], [nil,nil]], notNil: false) + } + + func testIsFull() { + func expect(grid : [[Int?]], isFull: Bool, notNil: Bool) { + let board = Board(withGrid: grid) + + if !notNil { + XCTAssertNil(board) + return + } + + XCTAssertNotNil(board) + XCTAssertEqual(board?.isFull(), isFull) + } + + expect(grid: [[1,2], [2,1]], isFull: true, notNil: true) + expect(grid: [[1,nil], [2,nil]], isFull: false, notNil: true) + expect(grid: [[1,2], [2,nil]], isFull: false, notNil: true) + expect(grid: [[1,nil], [2,1]], isFull: false, notNil: true) + } + + func testInsertPiece() { + func expect(grid : [[Int?]], idPlayer: Int, column: Int, boardResult : BoardResult, notNil: Bool) { + var board = Board(withGrid: grid) + + if !notNil { + XCTAssertNil(board) + return + } + + XCTAssertNotNil(board) + //XCTAssertEqual(board?.insertPiece(id: idPlayer, column: column), boardResult) + } + + expect(grid: [[1,nil], [2,nil]], idPlayer: 2, column: 0, boardResult: .ok, notNil: true) + } +} diff --git a/Src/Model/Tests/ModelTests/Human/HumanTests.swift b/Src/Model/Tests/ModelTests/Human/HumanTests.swift new file mode 100644 index 0000000..f78ef31 --- /dev/null +++ b/Src/Model/Tests/ModelTests/Human/HumanTests.swift @@ -0,0 +1,35 @@ +// +// HumanTests.swift +// +// +// Created by BREUIL Yohann on 11/02/2023. +// + +import XCTest + +final class HumanTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + 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. + // Any test you write for XCTest can be annotated as throws and async. + // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. + // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +}