Some refactor and tests

This commit is contained in:
cdricms
2024-06-27 19:13:13 +02:00
parent 8b5c2a592e
commit 8556380dba
5 changed files with 88 additions and 40 deletions

View File

@@ -14,7 +14,8 @@ final class EngineTests: XCTestCase {
rank -= 1
}
let pos: Square.Position = .init(rank: rank, file: file)
XCTAssertTrue(pos.index == Int(i), "Expected \(i) got \(pos.index!)")
XCTAssertTrue(
pos.index == Int(i), "Expected \(i) got \(pos.index!)")
}
}
func testDiagonalMoves() throws {
@@ -57,6 +58,53 @@ final class EngineTests: XCTestCase {
]
XCTAssertEqual(result, r.pseudoLegalPositions)
}
func testKingMoves() throws {
let k: King = .init(color: .White, on: .init(rank: 2, file: 8))
let result = [
Square.Position(rank: 3, file: 8),
Square.Position(rank: 1, file: 8),
Square.Position(rank: 1, file: 7),
Square.Position(rank: 2, file: 7),
Square.Position(rank: 3, file: 7),
]
XCTAssertEqual(result, k.pseudoLegalPositions)
}
func testKnightMoves() throws {
let n: Knight = .init(color: .White, on: .init(rank: 4, file: 4))
let result = [
Square.Position(rank: 6, file: 5),
Square.Position(rank: 6, file: 3),
Square.Position(rank: 2, file: 5),
Square.Position(rank: 2, file: 3),
Square.Position(rank: 5, file: 6),
Square.Position(rank: 5, file: 2),
Square.Position(rank: 3, file: 6),
Square.Position(rank: 3, file: 2),
]
XCTAssertEqual(result, n.pseudoLegalPositions)
}
func testPawnMoves() throws {
let pw: Pawn = .init(color: .White, on: .init(rank: 4, file: 4))
var result = [
Square.Position(rank: 5, file: 4),
Square.Position(rank: 6, file: 4),
Square.Position(rank: 5, file: 5),
Square.Position(rank: 5, file: 3),
]
XCTAssertEqual(result, pw.pseudoLegalPositions)
let pb: Pawn = .init(color: .Black, on: .init(rank: 4, file: 4))
result = [
Square.Position(rank: 3, file: 4),
Square.Position(rank: 2, file: 4),
Square.Position(rank: 3, file: 5),
Square.Position(rank: 3, file: 3),
]
XCTAssertEqual(result, pb.pseudoLegalPositions)
}
// func testBoard() throws {
// let board = Board()
// }