You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.5 KiB
80 lines
2.5 KiB
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)
|
|
}
|
|
}
|