Skip to content

Commit

Permalink
Mark test classes final and fix indentation in test files
Browse files Browse the repository at this point in the history
  • Loading branch information
pdil committed Aug 3, 2024
1 parent 3c13f56 commit d82ebf2
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 87 deletions.
22 changes: 11 additions & 11 deletions Tests/ChessKitTests/BoardTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
@testable import ChessKit
import XCTest

class BoardTests: XCTestCase {
final class BoardTests: XCTestCase {

func testEnPassant() {
var board = Board(position: .ep)
let ep = board.position.enPassant!

let capturingPiece = board.position.piece(at: .f4)!
XCTAssertTrue(ep.couldBeCaptured(by: capturingPiece))

let move = board.move(pieceAt: .f4, to: ep.captureSquare)!
XCTAssertEqual(move.result, .capture(ep.pawn))
}
Expand All @@ -34,7 +34,7 @@ class BoardTests: XCTestCase {
XCTAssertTrue(board.position.enPassantIsPossible)
}

func testWhitePromotion() {
func testWhitePromotion() {
let pawn = Piece(.pawn, color: .white, square: .e7)
let queen = Piece(.queen, color: .white, square: .e8)
var board = Board(position: .init(pieces: [pawn]))
Expand Down Expand Up @@ -126,26 +126,26 @@ class BoardTests: XCTestCase {
func testInsufficientMaterialScenarios() {
// different promotions
let fen = "k7/7P/8/8/8/8/8/K7 w - - 0 1"

let validPieces: [Piece.Kind] = [.rook, .queen]
let invalidPieces: [Piece.Kind] = [.bishop, .knight]

for p in validPieces {
var board = Board(position: .init(fen: fen)!)
let move = board.move(pieceAt: .h7, to: .h8)!

board.completePromotion(of: move , to: p)
XCTAssertFalse(board.position.hasInsufficientMaterial)
}

for p in invalidPieces {
var board = Board(position: .init(fen: fen)!)
let move = board.move(pieceAt: .h7, to: .h8)!

board.completePromotion(of: move , to: p)
XCTAssertTrue(board.position.hasInsufficientMaterial)
}

// opposite color bishops VS same color bishops
let fen2 = "k5B1/b7/1b6/8/8/8/8/K7 w - - 0 1"
let fen3 = "k5B1/1b6/2b5/8/8/8/8/K7 w - - 0 1"
Expand Down Expand Up @@ -197,7 +197,7 @@ class BoardTests: XCTestCase {

board.delegate = delegate
board.move(pieceAt: .f6, to: .g8) // 3rd time position occurs

waitForExpectations(timeout: 1.0)
}

Expand Down Expand Up @@ -362,7 +362,7 @@ class BoardTests: XCTestCase {

waitForExpectations(timeout: 1.0)
}

func testSideToMove() {
var position = Position.standard
XCTAssertEqual(position.sideToMove, .white)
Expand Down
24 changes: 12 additions & 12 deletions Tests/ChessKitTests/CastlingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
@testable import ChessKit
import XCTest

class CastlingTests: XCTestCase {

final class CastlingTests: XCTestCase {
func testCastling() {
var board = Board(position: .castling)
XCTAssertTrue(board.position.legalCastlings.contains(.bK))
XCTAssertFalse(board.position.legalCastlings.contains(.wK))
XCTAssertFalse(board.position.legalCastlings.contains(.bQ))
XCTAssertTrue(board.position.legalCastlings.contains(.wQ))

// white queenside castle
let wQmove = board.move(pieceAt: .e1, to: .c1)!
XCTAssertEqual(wQmove.result, .castle(.wQ))

// black kingside castle
let bkMove = board.move(pieceAt: .e8, to: .g8)!
XCTAssertEqual(bkMove.result, .castle(.bK))
}

func testInvalidCastling() {
let position = Position(
pieces: [
Expand All @@ -33,19 +33,19 @@ class CastlingTests: XCTestCase {
]
)
var board = Board(position: position)

// attempt to castle while in check
XCTAssertFalse(board.canMove(pieceAt: .e1, to: .g1))

// attempt to castle through check
board.move(pieceAt: .e8, to: .f8)
XCTAssertFalse(board.canMove(pieceAt: .e1, to: .g1))

// valid castling move
board.move(pieceAt: .f8, to: .h8)
XCTAssertTrue(board.canMove(pieceAt: .e1, to: .g1))
}

func testInvalidCastlingThroughPiece() {
let position = Position(
pieces: [
Expand All @@ -55,13 +55,13 @@ class CastlingTests: XCTestCase {
]
)
var board = Board(position: position)

// attempt to castle through another piece
XCTAssertFalse(board.canMove(pieceAt: .e1, to: .g1))

// valid castling move
board.move(pieceAt: .f1, to: .c4)
XCTAssertTrue(board.canMove(pieceAt: .e1, to: .g1))
}

}
14 changes: 7 additions & 7 deletions Tests/ChessKitTests/GameTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@testable import ChessKit
import XCTest

class GameTests: XCTestCase {
final class GameTests: XCTestCase {

private var game = Game()

Expand Down Expand Up @@ -214,7 +214,7 @@ class GameTests: XCTestCase {
.forward
]
)

XCTAssertEqual(
path.map(\.index),
[
Expand All @@ -230,7 +230,7 @@ class GameTests: XCTestCase {
}

func testPGN() {
let pgn =
let pgn =
"""
[Event "Test Event"]
[Site "Barrow, Alaska USA"]
Expand All @@ -249,7 +249,7 @@ class GameTests: XCTestCase {
[SetUp "1"]
[TestKey1 "Test Value 1"]
[TestKey2 "Test Value 2"]
1. e4 e5 2. Nf3 (2. Nc3 Nf6 (2... Nc6 3. f4) 3. Bc4) Nc6 (2... f5 3. exf5) 3. Bc4
"""

Expand All @@ -266,7 +266,7 @@ class GameTests: XCTestCase {
[White "Player One"]
[Black "Player Two"]
[Result "1-0"]
1. e4 e5 2. Nf3 (2. Nc3 Nf6 (2... Nc6 3. f4) 3. Bc4) Nc6 (2... f5 3. exf5) 3. Bc4
"""

Expand All @@ -278,7 +278,7 @@ class GameTests: XCTestCase {
let pgn =
"""
[Event "Test Event"]
1. e4 e5 2. Nf3 (2. Nc3 Nf6 (2... Nc6 3. f4) 3. Bc4) Nc6 (2... f5 3. exf5) 3. Bc4
"""

Expand All @@ -288,7 +288,7 @@ class GameTests: XCTestCase {
}

func testInvalidGame() {

}

}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ChessKitTests/MoveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@testable import ChessKit
import XCTest

class MoveTests: XCTestCase {
final class MoveTests: XCTestCase {

func testMoveSANInit() {
let move = Move(result: .move, piece: .init(.pawn, color: .white, square: .e4), start: .e2, end: .e4)
Expand Down
6 changes: 3 additions & 3 deletions Tests/ChessKitTests/MoveTreeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@testable import ChessKit
import XCTest

class MoveTreeTests: XCTestCase {
final class MoveTreeTests: XCTestCase {

func testEmptyCollection() {
let moveTree = MoveTree()
Expand Down Expand Up @@ -76,13 +76,13 @@ extension MoveTreeTests {

XCTAssertEqual(moveTree.previousIndex(for: i1), moveTree.index(before: i1))
XCTAssertEqual(moveTree.nextIndex(for: i1), moveTree.index(after: i1))

XCTAssertEqual(moveTree.move(at: i1), moveTree[i1])
XCTAssertEqual(moveTree.move(at: i1), move1)

XCTAssertEqual(moveTree.move(at: i2), moveTree[i2])
XCTAssertEqual(moveTree.move(at: i2), move2)

XCTAssertNil(moveTree.previousIndex(for: .minimum))
XCTAssertNil(moveTree.nextIndex(for: i2))

Expand Down
30 changes: 15 additions & 15 deletions Tests/ChessKitTests/Parsers/EngineLANParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,61 @@
@testable import ChessKit
import XCTest

class EngineLANParserTests: XCTestCase {

final class EngineLANParserTests: XCTestCase {
func testCapture() {
let position = Position(fen: "8/8/8/4p3/3P4/8/8/8 w - - 0 1")!
let move = EngineLANParser.parse(move: "d4e5", for: .white, in: position)

let capturedPiece = Piece(.pawn, color: .black, square: .e5)
XCTAssertEqual(move?.result, .capture(capturedPiece))
}

func testCastling() {
let p1 = Position(fen: "8/8/8/8/8/8/8/4K2R w KQ - 0 1")!
let wShortCastle = EngineLANParser.parse(move: "e1g1", for: .white, in: p1)
XCTAssertEqual(wShortCastle?.result, .castle(.wK))

let p2 = Position(fen: "8/8/8/8/8/8/8/R3K3 w KQ - 0 1")!
let wLongCastle = EngineLANParser.parse(move: "e1c1", for: .white, in: p2)
XCTAssertEqual(wLongCastle?.result, .castle(.wQ))

let p3 = Position(fen: "4k2r/8/8/8/8/8/8/8 b kq - 0 1")!
let bShortCastle = EngineLANParser.parse(move: "e8g8", for: .black, in: p3)
XCTAssertEqual(bShortCastle?.result, .castle(.bK))

let p4 = Position(fen: "r3k3/8/8/8/8/8/8/8 b kq - 0 1")!
let bLongCastle = EngineLANParser.parse(move: "e8c8", for: .black, in: p4)
XCTAssertEqual(bLongCastle?.result, .castle(.bQ))
}

func testPromotion() {
let p = Position(fen: "8/P7/8/8/8/8/8/8 w - - 0 1")!

let qPromotion = EngineLANParser.parse(move: "a7a8q", for: .white, in: p)
let promotedQueen = Piece(.queen, color: .white, square: .a8)
XCTAssertEqual(qPromotion?.promotedPiece, promotedQueen)

let rPromotion = EngineLANParser.parse(move: "a7a8r", for: .white, in: p)
let promotedRook = Piece(.rook, color: .white, square: .a8)
XCTAssertEqual(rPromotion?.promotedPiece, promotedRook)

let bPromotion = EngineLANParser.parse(move: "a7a8b", for: .white, in: p)
let promotedBishop = Piece(.bishop, color: .white, square: .a8)
XCTAssertEqual(bPromotion?.promotedPiece, promotedBishop)

let nPromotion = EngineLANParser.parse(move: "a7a8n", for: .white, in: p)
let promotedKnight = Piece(.knight, color: .white, square: .a8)
XCTAssertEqual(nPromotion?.promotedPiece, promotedKnight)
}

func testValidLANButInvalidMove() {
XCTAssertNil(EngineLANParser.parse(move: "a4b5", for: .white, in: .standard))
XCTAssertNil(EngineLANParser.parse(move: "f8b5", for: .black, in: .standard))
}

func testInvalidLAN() {
XCTAssertNil(EngineLANParser.parse(move: "bad move", for: .white, in: .standard))
}

}
Loading

0 comments on commit d82ebf2

Please sign in to comment.