test/test-fen.c

changeset 222
6388f9340a09
parent 221
338795f5837b
equal deleted inserted replaced
221:338795f5837b 222:6388f9340a09
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_stalemate) {
195 const char * fen = "8/8/kBK5/P7/8/8/8/8 b - - 6 57";
196 GameState gs;
197 int result = fen_parse(fen, &gs);
198 CX_TEST_DO {
199 CX_TEST_ASSERT(result == 0);
200 CX_TEST_ASSERT(strcmp(gs.fen_start, fen) == 0);
201 CX_TEST_ASSERT(gs.fifty_cntr_start == 6);
202 CX_TEST_ASSERT(gs.move_start == 113);
203 CX_TEST_ASSERT(current_color(&gs) == BLACK);
204 CX_TEST_ASSERT(gs.stalemate);
205 CX_TEST_ASSERT(!gs.threefold);
206 CX_TEST_ASSERT(!gs.nomaterial);
207 CX_TEST_ASSERT(!gs.remis);
208 CX_TEST_ASSERT(!gs.wresign);
209 CX_TEST_ASSERT(!gs.bresign);
210 CX_TEST_ASSERT(!gs.ragequit);
211 CX_TEST_ASSERT(!gs.review);
212 CX_TEST_ASSERT(!gs.checkmate);
213 /* check that we get the original FEN back */
214 char fen_chk[FEN_MAX_LENGTH];
215 fen_compute(fen_chk, &gs);
216 CX_TEST_ASSERTM(strcmp(fen, fen_chk) == 0, fen_chk);
217 }
218 gamestate_cleanup(&gs);
219 }
220
221 static CX_TEST(test_fen_nomaterial) {
222 const char * fen = "8/5K1k/8/8/8/8/8/8 w - - 0 77";
223 GameState gs;
224 int result = fen_parse(fen, &gs);
225 CX_TEST_DO {
226 CX_TEST_ASSERT(result == 0);
227 CX_TEST_ASSERT(strcmp(gs.fen_start, fen) == 0);
228 CX_TEST_ASSERT(gs.fifty_cntr_start == 0);
229 CX_TEST_ASSERT(gs.move_start == 152);
230 CX_TEST_ASSERT(current_color(&gs) == WHITE);
231 CX_TEST_ASSERT(!gs.stalemate);
232 CX_TEST_ASSERT(!gs.threefold);
233 CX_TEST_ASSERT(gs.nomaterial);
234 CX_TEST_ASSERT(!gs.remis);
235 CX_TEST_ASSERT(!gs.wresign);
236 CX_TEST_ASSERT(!gs.bresign);
237 CX_TEST_ASSERT(!gs.ragequit);
238 CX_TEST_ASSERT(!gs.review);
239 CX_TEST_ASSERT(!gs.checkmate);
240 /* check that we get the original FEN back */
241 char fen_chk[FEN_MAX_LENGTH];
242 fen_compute(fen_chk, &gs);
243 CX_TEST_ASSERTM(strcmp(fen, fen_chk) == 0, fen_chk);
244 }
245 gamestate_cleanup(&gs);
246 }
247
194 static CX_TEST(test_fen_enpassant) { 248 static CX_TEST(test_fen_enpassant) {
195 /* this test contains a full game where white is checkmated */ 249 /* 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"; 250 const char * fen = "rnQ4r/pp4kp/3p2pn/1BpPp1N1/5P2/2BK4/P1P3qP/8 w - e6 0 19";
197 GameState gs; 251 GameState gs;
198 int result = fen_parse(fen, &gs); 252 int result = fen_parse(fen, &gs);
221 CxTestSuite* suite = cx_test_suite_new("Test FEN API"); 275 CxTestSuite* suite = cx_test_suite_new("Test FEN API");
222 276
223 cx_test_register(suite, test_fen_basic); 277 cx_test_register(suite, test_fen_basic);
224 cx_test_register(suite, test_fen_with_castling_rights); 278 cx_test_register(suite, test_fen_with_castling_rights);
225 cx_test_register(suite, test_fen_checkmate); 279 cx_test_register(suite, test_fen_checkmate);
226 // TODO: test FENs that describe stalemate, threefold, no-material positions 280 cx_test_register(suite, test_fen_stalemate);
281 cx_test_register(suite, test_fen_nomaterial);
227 cx_test_register(suite, test_fen_enpassant); 282 cx_test_register(suite, test_fen_enpassant);
228 283
229 return suite; 284 return suite;
230 } 285 }

mercurial