From d82ebf2f23cfeab3736c2a824f4e0dd75a4cae22 Mon Sep 17 00:00:00 2001 From: Paolo Di Lorenzo Date: Sat, 3 Aug 2024 12:17:26 -0400 Subject: [PATCH] Mark test classes final and fix indentation in test files --- Tests/ChessKitTests/BoardTests.swift | 22 ++++++------ Tests/ChessKitTests/CastlingTests.swift | 24 ++++++------- Tests/ChessKitTests/GameTests.swift | 14 ++++---- Tests/ChessKitTests/MoveTests.swift | 2 +- Tests/ChessKitTests/MoveTreeTests.swift | 6 ++-- .../Parsers/EngineLANParserTests.swift | 30 ++++++++-------- .../Parsers/FENParserTests.swift | 34 +++++++++---------- .../Parsers/PGNParserTests.swift | 16 ++++----- .../Parsers/SANParserTests.swift | 2 +- .../Performance/BoardPerformanceTests.swift | 2 +- .../PGNParserPerformanceTests.swift | 6 ++-- Tests/ChessKitTests/PieceTests.swift | 4 +-- Tests/ChessKitTests/SpecialMoveTests.swift | 4 +-- Tests/ChessKitTests/SquareTests.swift | 6 ++-- .../Utilities/MockBoardDelegate.swift | 2 +- 15 files changed, 87 insertions(+), 87 deletions(-) diff --git a/Tests/ChessKitTests/BoardTests.swift b/Tests/ChessKitTests/BoardTests.swift index 55000af..4838adf 100644 --- a/Tests/ChessKitTests/BoardTests.swift +++ b/Tests/ChessKitTests/BoardTests.swift @@ -6,7 +6,7 @@ @testable import ChessKit import XCTest -class BoardTests: XCTestCase { +final class BoardTests: XCTestCase { func testEnPassant() { var board = Board(position: .ep) @@ -14,7 +14,7 @@ class BoardTests: XCTestCase { 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)) } @@ -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])) @@ -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" @@ -197,7 +197,7 @@ class BoardTests: XCTestCase { board.delegate = delegate board.move(pieceAt: .f6, to: .g8) // 3rd time position occurs - + waitForExpectations(timeout: 1.0) } @@ -362,7 +362,7 @@ class BoardTests: XCTestCase { waitForExpectations(timeout: 1.0) } - + func testSideToMove() { var position = Position.standard XCTAssertEqual(position.sideToMove, .white) diff --git a/Tests/ChessKitTests/CastlingTests.swift b/Tests/ChessKitTests/CastlingTests.swift index c026ba6..f506f38 100644 --- a/Tests/ChessKitTests/CastlingTests.swift +++ b/Tests/ChessKitTests/CastlingTests.swift @@ -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: [ @@ -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: [ @@ -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)) } - + } diff --git a/Tests/ChessKitTests/GameTests.swift b/Tests/ChessKitTests/GameTests.swift index 27b350a..aabc6d7 100644 --- a/Tests/ChessKitTests/GameTests.swift +++ b/Tests/ChessKitTests/GameTests.swift @@ -6,7 +6,7 @@ @testable import ChessKit import XCTest -class GameTests: XCTestCase { +final class GameTests: XCTestCase { private var game = Game() @@ -214,7 +214,7 @@ class GameTests: XCTestCase { .forward ] ) - + XCTAssertEqual( path.map(\.index), [ @@ -230,7 +230,7 @@ class GameTests: XCTestCase { } func testPGN() { - let pgn = + let pgn = """ [Event "Test Event"] [Site "Barrow, Alaska USA"] @@ -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 """ @@ -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 """ @@ -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 """ @@ -288,7 +288,7 @@ class GameTests: XCTestCase { } func testInvalidGame() { - + } } diff --git a/Tests/ChessKitTests/MoveTests.swift b/Tests/ChessKitTests/MoveTests.swift index f21c01d..7998abb 100644 --- a/Tests/ChessKitTests/MoveTests.swift +++ b/Tests/ChessKitTests/MoveTests.swift @@ -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) diff --git a/Tests/ChessKitTests/MoveTreeTests.swift b/Tests/ChessKitTests/MoveTreeTests.swift index 5f1d1ec..9826458 100644 --- a/Tests/ChessKitTests/MoveTreeTests.swift +++ b/Tests/ChessKitTests/MoveTreeTests.swift @@ -6,7 +6,7 @@ @testable import ChessKit import XCTest -class MoveTreeTests: XCTestCase { +final class MoveTreeTests: XCTestCase { func testEmptyCollection() { let moveTree = MoveTree() @@ -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)) diff --git a/Tests/ChessKitTests/Parsers/EngineLANParserTests.swift b/Tests/ChessKitTests/Parsers/EngineLANParserTests.swift index 4066fd5..d4bd431 100644 --- a/Tests/ChessKitTests/Parsers/EngineLANParserTests.swift +++ b/Tests/ChessKitTests/Parsers/EngineLANParserTests.swift @@ -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)) } - + } diff --git a/Tests/ChessKitTests/Parsers/FENParserTests.swift b/Tests/ChessKitTests/Parsers/FENParserTests.swift index e020c34..d8ca06a 100644 --- a/Tests/ChessKitTests/Parsers/FENParserTests.swift +++ b/Tests/ChessKitTests/Parsers/FENParserTests.swift @@ -6,11 +6,11 @@ @testable import ChessKit import XCTest -class FENParserTests: XCTestCase { - +final class FENParserTests: XCTestCase { + func testStandardStartingPosition() { let p = Position.standard - + XCTAssertEqual(p.pieces.count, 32) XCTAssertEqual(p.sideToMove, .white) XCTAssertEqual(p.legalCastlings, LegalCastlings(legal: [.bK, .wK, .bQ, .wQ])) @@ -18,17 +18,17 @@ class FENParserTests: XCTestCase { XCTAssertEqual(p.clock.halfmoves, 0) XCTAssertEqual(p.clock.fullmoves, 1) } - + func testComplexPiecePlacement() { let p = Position.complex - + XCTAssertEqual(p.pieces.count, 24) XCTAssertEqual(p.sideToMove, .black) XCTAssertEqual(p.legalCastlings, LegalCastlings(legal: [.bK, .bQ])) XCTAssertNil(p.enPassant) XCTAssertEqual(p.clock.halfmoves, 0) XCTAssertEqual(p.clock.fullmoves, 20) - + // pieces XCTAssertTrue(p.pieces.contains(Piece(.rook, color: .black, square: .a8))) XCTAssertTrue(p.pieces.contains(Piece(.bishop, color: .black, square: .c8))) @@ -55,23 +55,23 @@ class FENParserTests: XCTestCase { XCTAssertTrue(p.pieces.contains(Piece(.queen, color: .black, square: .a1))) XCTAssertTrue(p.pieces.contains(Piece(.bishop, color: .black, square: .g1))) } - + func testEnPassantPosition() { let whiteEP = Position(fen: "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1")! - + XCTAssertEqual(whiteEP.sideToMove, .black) XCTAssertEqual(whiteEP.enPassant, EnPassant(pawn: Piece(.pawn, color: .white, square: .e4))) - + let blackEP = Position(fen: "rnbqkbnr/pppppppp/8/4P3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq e6 0 2")! - + XCTAssertEqual(blackEP.sideToMove, .white) XCTAssertEqual(blackEP.enPassant, EnPassant(pawn: Piece(.pawn, color: .black, square: .e5))) } - + func testInvalidFen() { let p = Position(fen: "invalid") XCTAssertNil(p) - + let invalidSideToMove = Position(fen: "8/8/8/4p1K1/2k1P3/8/8/8 B - - 0 1")! XCTAssertEqual(invalidSideToMove.sideToMove, .white) } @@ -79,18 +79,18 @@ class FENParserTests: XCTestCase { func testConvertPosition() { let standardFen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" XCTAssertEqual(Position.standard.fen, standardFen) - + let complexFen = "r1b1k1nr/p2p1pNp/n2B4/1p1NP2P/6P1/3P1Q2/P1P1K3/q5b1 b kq - 0 20" XCTAssertEqual(Position.complex.fen, complexFen) - + let epFen = "rnbqkbnr/ppppp1pp/8/8/4Pp2/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1" XCTAssertEqual(Position.ep.fen, epFen) - + let castlingFen = "4k2r/6r1/8/8/8/8/3R4/R3K3 w Qk - 0 1" XCTAssertEqual(Position.castling.fen, castlingFen) - + let fiftyMoveFen = "8/5k2/3p4/1p1Pp2p/pP2Pp1P/P4P1K/8/8 b - - 99 50" XCTAssertEqual(Position.fiftyMove.fen, fiftyMoveFen) } - + } diff --git a/Tests/ChessKitTests/Parsers/PGNParserTests.swift b/Tests/ChessKitTests/Parsers/PGNParserTests.swift index 3930141..b149e1f 100644 --- a/Tests/ChessKitTests/Parsers/PGNParserTests.swift +++ b/Tests/ChessKitTests/Parsers/PGNParserTests.swift @@ -6,18 +6,18 @@ @testable import ChessKit import XCTest -class PGNParserTests: XCTestCase { - +final class PGNParserTests: XCTestCase { + func testGameFromPGN() { let game = PGNParser.parse(game: Game.fischerSpassky) let gameFromPGN = Game(pgn: Game.fischerSpassky) - + XCTAssertEqual(game, gameFromPGN) } - + func testTagParsing() { let game = PGNParser.parse(game: Game.fischerSpassky) - + // tags XCTAssertEqual(game?.tags.event, "F/S Return Match") XCTAssertEqual(game?.tags.site, "Belgrade, Serbia JUG") @@ -27,10 +27,10 @@ class PGNParserTests: XCTestCase { XCTAssertEqual(game?.tags.black, "Spassky, Boris V.") XCTAssertEqual(game?.tags.result, "1/2-1/2") } - + func testMoveTextParsing() { let game = PGNParser.parse(game: Game.fischerSpassky) - + // starting position + 85 ply XCTAssertEqual(game?.positions.keys.count, 86) @@ -67,5 +67,5 @@ class PGNParserTests: XCTestCase { color: .white )]?.checkState, .check) } - + } diff --git a/Tests/ChessKitTests/Parsers/SANParserTests.swift b/Tests/ChessKitTests/Parsers/SANParserTests.swift index 630503c..1a2903e 100644 --- a/Tests/ChessKitTests/Parsers/SANParserTests.swift +++ b/Tests/ChessKitTests/Parsers/SANParserTests.swift @@ -6,7 +6,7 @@ @testable import ChessKit import XCTest -class SANParserTests: XCTestCase { +final class SANParserTests: XCTestCase { func testCastling() { let p1 = Position(fen: "r3k3/8/8/8/8/8/8/4K2R w Kq - 0 1")! diff --git a/Tests/ChessKitTests/Performance/BoardPerformanceTests.swift b/Tests/ChessKitTests/Performance/BoardPerformanceTests.swift index ec9db27..7507298 100644 --- a/Tests/ChessKitTests/Performance/BoardPerformanceTests.swift +++ b/Tests/ChessKitTests/Performance/BoardPerformanceTests.swift @@ -267,7 +267,7 @@ final class BoardPerformanceTests: XCTestCase { board.move(pieceAt: .h3, to: .f2) XCTAssertEqual(board.position.fen, "8/8/R5p1/2k2bp1/1p6/1P3PP1/3K1n2/8 w - - 6 42") - + board.move(pieceAt: .g3, to: .g4) XCTAssertEqual(board.position.fen, "8/8/R5p1/2k2bp1/1p4P1/1P3P2/3K1n2/8 b - - 0 42") diff --git a/Tests/ChessKitTests/Performance/PGNParserPerformanceTests.swift b/Tests/ChessKitTests/Performance/PGNParserPerformanceTests.swift index 3b263f5..4b46bff 100644 --- a/Tests/ChessKitTests/Performance/PGNParserPerformanceTests.swift +++ b/Tests/ChessKitTests/Performance/PGNParserPerformanceTests.swift @@ -7,7 +7,7 @@ import XCTest final class PGNParserPerformanceTests: XCTestCase { - + func testBoardPerformance() { measure( metrics: [ @@ -18,10 +18,10 @@ final class PGNParserPerformanceTests: XCTestCase { block: parsePGN ) } - + private func parsePGN() { let parsedGame = PGNParser.parse(game: Game.fischerSpassky) XCTAssertNotNil(parsedGame) } - + } diff --git a/Tests/ChessKitTests/PieceTests.swift b/Tests/ChessKitTests/PieceTests.swift index ef166a2..626a8db 100644 --- a/Tests/ChessKitTests/PieceTests.swift +++ b/Tests/ChessKitTests/PieceTests.swift @@ -6,7 +6,7 @@ @testable import ChessKit import XCTest -class PieceTests: XCTestCase { +final class PieceTests: XCTestCase { func testNotation() { let pawn = Piece.Kind.pawn @@ -85,7 +85,7 @@ class PieceTests: XCTestCase { XCTAssertEqual(bN?.color, .black) XCTAssertEqual(bN?.kind, .knight) XCTAssertEqual(bN?.square, sq) - + let bR = Piece(fen: "r", square: sq) XCTAssertEqual(bR?.color, .black) XCTAssertEqual(bR?.kind, .rook) diff --git a/Tests/ChessKitTests/SpecialMoveTests.swift b/Tests/ChessKitTests/SpecialMoveTests.swift index 13c08d7..d5c5528 100644 --- a/Tests/ChessKitTests/SpecialMoveTests.swift +++ b/Tests/ChessKitTests/SpecialMoveTests.swift @@ -6,7 +6,7 @@ @testable import ChessKit import XCTest -class SpecialMoveTests: XCTestCase { +final class SpecialMoveTests: XCTestCase { func testLegalCastlingInvalidationForKings() { let blackKing = Piece(.king, color: .black, square: .e8) @@ -57,7 +57,7 @@ class SpecialMoveTests: XCTestCase { XCTAssertFalse(legalCastlings.contains(.wK)) XCTAssertFalse(legalCastlings.contains(.wQ)) } - + func testEnPassantCaptureSquare() { let blackPawn = Piece(.pawn, color: .black, square: .d5) let blackEnPassant = EnPassant(pawn: blackPawn) diff --git a/Tests/ChessKitTests/SquareTests.swift b/Tests/ChessKitTests/SquareTests.swift index 3a2391e..8fed7ff 100644 --- a/Tests/ChessKitTests/SquareTests.swift +++ b/Tests/ChessKitTests/SquareTests.swift @@ -6,7 +6,7 @@ @testable import ChessKit import XCTest -class SquareTests: XCTestCase { +final class SquareTests: XCTestCase { func testNotation() { XCTAssertEqual(Square.a1.notation, "a1") @@ -23,7 +23,7 @@ class SquareTests: XCTestCase { func testInvalidNotation() { XCTAssertEqual(Square("invalid"), .a1) } - + func testSquareColor() { XCTAssertEqual(Square.a1.color, .dark) XCTAssertEqual(Square.h1.color, .light) @@ -54,7 +54,7 @@ class SquareTests: XCTestCase { XCTAssertEqual(Square.a1.left, .a1) XCTAssertEqual(Square.b1.left, .a1) XCTAssertEqual(Square.h1.left, .g1) - + XCTAssertEqual(Square.a1.right, .b1) XCTAssertEqual(Square.g1.right, .h1) XCTAssertEqual(Square.h1.right, .h1) diff --git a/Tests/ChessKitTests/Utilities/MockBoardDelegate.swift b/Tests/ChessKitTests/Utilities/MockBoardDelegate.swift index bb2e5ca..8f91d1a 100644 --- a/Tests/ChessKitTests/Utilities/MockBoardDelegate.swift +++ b/Tests/ChessKitTests/Utilities/MockBoardDelegate.swift @@ -20,7 +20,7 @@ final class MockBoardDelegate: BoardDelegate { func didPromote(with move: Move) { didPromote?(move) } - + func didEnd(with result: Board.EndResult) { didEnd?(result) }