test/test-fen.c

changeset 221
338795f5837b
parent 220
04da225a5677
child 222
6388f9340a09
equal deleted inserted replaced
220:04da225a5677 221:338795f5837b
189 CX_TEST_ASSERTM(strcmp(fen, fen_chk) == 0, fen_chk); 189 CX_TEST_ASSERTM(strcmp(fen, fen_chk) == 0, fen_chk);
190 } 190 }
191 gamestate_cleanup(&gs); 191 gamestate_cleanup(&gs);
192 } 192 }
193 193
194 static CX_TEST(test_fen_enpassant) {
195 /* this test contains a full game where white is checkmated */
196 const char * fen = "rnQ4r/pp4kp/3p2pn/1BpPp1N1/5P2/2BK4/P1P3qP/8 w - e6 0 19";
197 GameState gs;
198 int result = fen_parse(fen, &gs);
199 CX_TEST_DO {
200 CX_TEST_ASSERT(result == 0);
201 /* verify that only e5 has an active enpassant threat */
202 for (File f = 0 ; f < 8 ; f++) {
203 for (Rank r = 0 ; r < 8 ; r++) {
204 if (f == fileidx('e') && r == rankidx('5')) {
205 CX_TEST_ASSERT(enpassant_threat_exists(&gs, f, r));
206 } else {
207 CX_TEST_ASSERT(!enpassant_threat_exists(&gs, f, r));
208 }
209 }
210 }
211
212 /* check that we get the original FEN back */
213 char fen_chk[FEN_MAX_LENGTH];
214 fen_compute(fen_chk, &gs);
215 CX_TEST_ASSERTM(strcmp(fen, fen_chk) == 0, fen_chk);
216 }
217 gamestate_cleanup(&gs);
218 }
219
194 CxTestSuite* test_fen_suite(void) { 220 CxTestSuite* test_fen_suite(void) {
195 CxTestSuite* suite = cx_test_suite_new("Test FEN API"); 221 CxTestSuite* suite = cx_test_suite_new("Test FEN API");
196 222
197 cx_test_register(suite, test_fen_basic); 223 cx_test_register(suite, test_fen_basic);
198 cx_test_register(suite, test_fen_with_castling_rights); 224 cx_test_register(suite, test_fen_with_castling_rights);
199 cx_test_register(suite, test_fen_checkmate); 225 cx_test_register(suite, test_fen_checkmate);
200 // TODO: test FENs that describe stalemate, threefold, no-material positions 226 // TODO: test FENs that describe stalemate, threefold, no-material positions
201 // TODO: test FEN with en-passant threat 227 cx_test_register(suite, test_fen_enpassant);
202 228
203 return suite; 229 return suite;
204 } 230 }

mercurial