| 95 } |
95 } |
| 96 gamestate_cleanup(&gs); |
96 gamestate_cleanup(&gs); |
| 97 } |
97 } |
| 98 |
98 |
| 99 static CX_TEST(test_fen_with_castling_rights) { |
99 static CX_TEST(test_fen_with_castling_rights) { |
| 100 /* a test that simply checks if an arbitrary FEN is parsed correctly */ |
100 /* this test contains castling rights and a non-zero fifty-moves counter */ |
| 101 const char * fen = "1rbqk1nr/ppp2ppp/2np4/2b1p3/2P5/2N1P1P1/PP1P1PBP/R1BQK1NR w KQk - 1 6"; |
101 const char * fen = "1rbqk1nr/ppp2ppp/2np4/2b1p3/2P5/2N1P1P1/PP1P1PBP/R1BQK1NR w KQk - 1 6"; |
| 102 Board expected_board = { |
102 Board expected_board = { |
| 103 {WROOK, 0, WBISHOP, WQUEEN, WKING, 0, WKNIGHT, WROOK}, |
103 {WROOK, 0, WBISHOP, WQUEEN, WKING, 0, WKNIGHT, WROOK}, |
| 104 {WPAWN, WPAWN, 0, WPAWN, 0, WPAWN, WBISHOP, WPAWN}, |
104 {WPAWN, WPAWN, 0, WPAWN, 0, WPAWN, WBISHOP, WPAWN}, |
| 105 {0, 0, WKNIGHT, 0, WPAWN, 0, WPAWN, 0}, |
105 {0, 0, WKNIGHT, 0, WPAWN, 0, WPAWN, 0}, |
| 160 CX_TEST_ASSERTM(strcmp(fen, fen_chk) == 0, fen_chk); |
160 CX_TEST_ASSERTM(strcmp(fen, fen_chk) == 0, fen_chk); |
| 161 } |
161 } |
| 162 gamestate_cleanup(&gs); |
162 gamestate_cleanup(&gs); |
| 163 } |
163 } |
| 164 |
164 |
| |
165 static CX_TEST(test_fen_checkmate) { |
| |
166 /* this test contains a full game where white is checkmated */ |
| |
167 const char * fen = "5rk1/1pp4p/p1n3p1/4b1N1/8/1P1N4/P1P3P1/qKB4R w - - 2 26"; |
| |
168 GameState gs; |
| |
169 int result = fen_parse(fen, &gs); |
| |
170 CX_TEST_DO { |
| |
171 CX_TEST_ASSERT(result == 0); |
| |
172 CX_TEST_ASSERT(strcmp(gs.fen_start, fen) == 0); |
| |
173 CX_TEST_ASSERT(gs.fifty_cntr_start == 2); |
| |
174 CX_TEST_ASSERT(gs.move_start == 50); |
| |
175 CX_TEST_ASSERT(current_color(&gs) == WHITE); |
| |
176 CX_TEST_ASSERT(!gs.stalemate); |
| |
177 CX_TEST_ASSERT(!gs.threefold); |
| |
178 CX_TEST_ASSERT(!gs.nomaterial); |
| |
179 CX_TEST_ASSERT(!gs.remis); |
| |
180 CX_TEST_ASSERT(!gs.wresign); |
| |
181 CX_TEST_ASSERT(!gs.bresign); |
| |
182 CX_TEST_ASSERT(!gs.ragequit); |
| |
183 CX_TEST_ASSERT(!gs.review); |
| |
184 /* the checkmate flag must be set */ |
| |
185 CX_TEST_ASSERT(gs.checkmate); |
| |
186 /* check that we get the original FEN back */ |
| |
187 char fen_chk[FEN_MAX_LENGTH]; |
| |
188 fen_compute(fen_chk, &gs); |
| |
189 CX_TEST_ASSERTM(strcmp(fen, fen_chk) == 0, fen_chk); |
| |
190 } |
| |
191 gamestate_cleanup(&gs); |
| |
192 } |
| |
193 |
| 165 CxTestSuite* test_fen_suite(void) { |
194 CxTestSuite* test_fen_suite(void) { |
| 166 CxTestSuite* suite = cx_test_suite_new("Test FEN API"); |
195 CxTestSuite* suite = cx_test_suite_new("Test FEN API"); |
| 167 |
196 |
| 168 cx_test_register(suite, test_fen_basic); |
197 cx_test_register(suite, test_fen_basic); |
| 169 cx_test_register(suite, test_fen_with_castling_rights); |
198 cx_test_register(suite, test_fen_with_castling_rights); |
| 170 // TODO: test FENs that describe definitely ended games (for each type of ending) |
199 cx_test_register(suite, test_fen_checkmate); |
| |
200 // TODO: test FENs that describe stalemate, threefold, no-material positions |
| 171 // TODO: test FEN with en-passant threat |
201 // TODO: test FEN with en-passant threat |
| 172 |
202 |
| 173 return suite; |
203 return suite; |
| 174 } |
204 } |