--- a/test/test-fen.c Sat Sep 05 12:36:04 2026 +0200 +++ b/test/test-fen.c Sat Sep 05 13:03:09 2026 +0200 @@ -97,7 +97,7 @@ } static CX_TEST(test_fen_with_castling_rights) { - /* a test that simply checks if an arbitrary FEN is parsed correctly */ + /* this test contains castling rights and a non-zero fifty-moves counter */ const char * fen = "1rbqk1nr/ppp2ppp/2np4/2b1p3/2P5/2N1P1P1/PP1P1PBP/R1BQK1NR w KQk - 1 6"; Board expected_board = { {WROOK, 0, WBISHOP, WQUEEN, WKING, 0, WKNIGHT, WROOK}, @@ -162,12 +162,42 @@ gamestate_cleanup(&gs); } +static CX_TEST(test_fen_checkmate) { + /* this test contains a full game where white is checkmated */ + const char * fen = "5rk1/1pp4p/p1n3p1/4b1N1/8/1P1N4/P1P3P1/qKB4R w - - 2 26"; + GameState gs; + int result = fen_parse(fen, &gs); + CX_TEST_DO { + CX_TEST_ASSERT(result == 0); + CX_TEST_ASSERT(strcmp(gs.fen_start, fen) == 0); + CX_TEST_ASSERT(gs.fifty_cntr_start == 2); + CX_TEST_ASSERT(gs.move_start == 50); + CX_TEST_ASSERT(current_color(&gs) == WHITE); + CX_TEST_ASSERT(!gs.stalemate); + CX_TEST_ASSERT(!gs.threefold); + CX_TEST_ASSERT(!gs.nomaterial); + CX_TEST_ASSERT(!gs.remis); + CX_TEST_ASSERT(!gs.wresign); + CX_TEST_ASSERT(!gs.bresign); + CX_TEST_ASSERT(!gs.ragequit); + CX_TEST_ASSERT(!gs.review); + /* the checkmate flag must be set */ + CX_TEST_ASSERT(gs.checkmate); + /* check that we get the original FEN back */ + char fen_chk[FEN_MAX_LENGTH]; + fen_compute(fen_chk, &gs); + CX_TEST_ASSERTM(strcmp(fen, fen_chk) == 0, fen_chk); + } + gamestate_cleanup(&gs); +} + CxTestSuite* test_fen_suite(void) { CxTestSuite* suite = cx_test_suite_new("Test FEN API"); cx_test_register(suite, test_fen_basic); cx_test_register(suite, test_fen_with_castling_rights); - // TODO: test FENs that describe definitely ended games (for each type of ending) + cx_test_register(suite, test_fen_checkmate); + // TODO: test FENs that describe stalemate, threefold, no-material positions // TODO: test FEN with en-passant threat return suite;