improved test coverage

master
Kanken 2 years ago
parent 2235d524f1
commit 086bf2c0ea

@ -263,8 +263,8 @@
filePath = "forcesPack/Sources/forcesPack/Rules/AreRows4x.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "19"
endingLineNumber = "19"
startingLineNumber = "20"
endingLineNumber = "20"
landmarkName = "isRuleMet(grid:targetedRow:targetedCol:)"
landmarkType = "7">
</BreakpointContent>
@ -359,8 +359,8 @@
filePath = "forcesPack/Sources/forcesPack/Rules/AreCols4x.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "11"
endingLineNumber = "11"
startingLineNumber = "12"
endingLineNumber = "12"
landmarkName = "isRuleMet(grid:targetedRow:targetedCol:)"
landmarkType = "7">
</BreakpointContent>

@ -40,6 +40,10 @@ public class Game{
}
}
public convenience init(_ test: Int){
self.init([IA(id: 0), IA(id: 1)])
}
private func doGameLoop() -> Bool{
for p in players{
while(!board.insertPeice(id: p.id, row: p.play(board.nbCols-1))){}

@ -6,8 +6,9 @@
//
import Foundation
class AreCols4x: Rule{ //TODO: use the targeted row/col for more precision
func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool {
public class AreCols4x: Rule{ //TODO: use the targeted row/col for more precision
public init() {}
public func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool {
// print("rule: cols")
var i: Int = 0
var old: Int? = -1

@ -7,8 +7,9 @@
import Foundation
class AreDiags4x: Rule{ //TODO: use the targeted row/col for more precision
func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool {
public class AreDiags4x: Rule{ //TODO: use the targeted row/col for more precision
public init() {}
public func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool {
let colRange = 0...grid.count-1
let rowRange = 0...grid[0].count-1

@ -7,8 +7,9 @@
import Foundation
class AreRows4x: Rule{//TODO: use the targeted row/col for more precision
func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool {
public class AreRows4x: Rule{//TODO: use the targeted row/col for more precision
public init() {}
public func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int) -> Bool {
// print("rule: rows")
var i: [Int] = Array( repeating: 0, count: grid.count)
var old: [Int?] = Array( repeating: nil, count: grid.count)

@ -7,6 +7,6 @@
import Foundation
protocol Rule{
public protocol Rule{
func isRuleMet(grid: [[Int?]], targetedRow: Int, targetedCol: Int)-> Bool
}

@ -7,7 +7,7 @@
import Foundation
protocol nbRowsRule{
public protocol nbRowsRule{
var maxRow: Int { get }
var maxCol: Int { get }
}

@ -0,0 +1,16 @@
//
// File.swift
//
//
// Created by yorick geoffre on 07/02/2023.
//
import Foundation
import forcesPack
import XCTest
final class GameTests: XCTestCase{
public func testGame(){
XCTAssertNoThrow(Game(-1))
}
}

@ -26,5 +26,4 @@ final class PlayerTests: XCTestCase {
XCTAssertNotNil(p)
XCTAssertEqual(p.description, "Human 0")
}
}

@ -7,9 +7,34 @@
import Foundation
import XCTest
import forcesPack
final class BoardRulesTests: XCTestCase {
private var boardEmpty: [[Int?]] = [[nil,nil,nil,nil],[nil,nil,nil,nil],[nil,nil,nil,nil],[nil,nil,nil,nil]]
private var boardRow: [[Int?]] = [[0,0,0,0],[nil,nil,nil,nil],[nil,nil,nil,nil],[nil,nil,nil,nil]]
private var boardCol: [[Int?]] = [[0,nil,nil,nil],[0,nil,nil,nil],[0,nil,nil,nil],[0,nil,nil,nil]]
private var boardDiag: [[Int?]] = [[0,nil,nil,nil],[nil,0,nil,nil],[nil,nil,0,nil],[nil,nil,nil,0]]
func testRules(){
//let rule : Rule
var ruleCol : Rule = AreCols4x()
var ruleRow: Rule = AreRows4x()
var ruleDiag: Rule = AreDiags4x()
XCTAssertFalse(ruleCol.isRuleMet(grid: boardEmpty, targetedRow: 0, targetedCol: 0))
XCTAssertFalse(ruleRow.isRuleMet(grid: boardEmpty, targetedRow: 0, targetedCol: 0))
XCTAssertFalse(ruleDiag.isRuleMet(grid: boardEmpty, targetedRow: 0, targetedCol: 0))
XCTAssertTrue(ruleCol.isRuleMet(grid: boardRow, targetedRow: 0, targetedCol: 0))
XCTAssertFalse(ruleRow.isRuleMet(grid: boardRow, targetedRow: 0, targetedCol: 0))
XCTAssertFalse(ruleDiag.isRuleMet(grid: boardRow, targetedRow: 0, targetedCol: 0))
XCTAssertFalse(ruleCol.isRuleMet(grid: boardCol, targetedRow: 0, targetedCol: 0))
XCTAssertTrue(ruleRow.isRuleMet(grid: boardCol, targetedRow: 0, targetedCol: 0))
XCTAssertFalse(ruleDiag.isRuleMet(grid: boardCol, targetedRow: 0, targetedCol: 0))
XCTAssertFalse(ruleCol.isRuleMet(grid: boardDiag, targetedRow: 0, targetedCol: 0))
XCTAssertFalse(ruleRow.isRuleMet(grid: boardDiag, targetedRow: 0, targetedCol: 0))
XCTAssertTrue(ruleDiag.isRuleMet(grid: boardDiag, targetedRow: 0, targetedCol: 0))
}
}

Loading…
Cancel
Save