feat - ✨ add tests
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
78c4818516
commit
700d5e804e
@ -1,18 +1,21 @@
|
||||
/// Cclassic rules of Connect 4 game
|
||||
public class ClassicRules {
|
||||
public func isGameOver() -> (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#>
|
||||
// }
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue