Mon, 07 Sep 2026 17:01:21 +0200
FEN parser: add test cases for stalemate and no-material positions
relates to #939
| test/test-fen.c | file | annotate | diff | comparison | revisions |
--- a/test/test-fen.c Mon Sep 07 16:50:49 2026 +0200 +++ b/test/test-fen.c Mon Sep 07 17:01:21 2026 +0200 @@ -191,6 +191,60 @@ gamestate_cleanup(&gs); } +static CX_TEST(test_fen_stalemate) { + const char * fen = "8/8/kBK5/P7/8/8/8/8 b - - 6 57"; + 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 == 6); + CX_TEST_ASSERT(gs.move_start == 113); + CX_TEST_ASSERT(current_color(&gs) == BLACK); + 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); + 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); +} + +static CX_TEST(test_fen_nomaterial) { + const char * fen = "8/5K1k/8/8/8/8/8/8 w - - 0 77"; + 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 == 0); + CX_TEST_ASSERT(gs.move_start == 152); + 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); + 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); +} + static CX_TEST(test_fen_enpassant) { /* this test contains a full game where white is checkmated */ const char * fen = "rnQ4r/pp4kp/3p2pn/1BpPp1N1/5P2/2BK4/P1P3qP/8 w - e6 0 19"; @@ -223,7 +277,8 @@ cx_test_register(suite, test_fen_basic); cx_test_register(suite, test_fen_with_castling_rights); cx_test_register(suite, test_fen_checkmate); - // TODO: test FENs that describe stalemate, threefold, no-material positions + cx_test_register(suite, test_fen_stalemate); + cx_test_register(suite, test_fen_nomaterial); cx_test_register(suite, test_fen_enpassant); return suite;