Skip to content

Commit 5bcb2b6

Browse files
committed
Add test to enforce FEN strings for game
The test was found as a sample on: https://www.chessprogramming.org/Forsyth-Edwards_Notation The test exercises special-cases of: * En passant moves * Full move counter * Half move clock
1 parent d60d957 commit 5bcb2b6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/game.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,31 @@ pub fn fake_pgn_parser(moves: &str) -> Game {
488488
})
489489
}
490490

491+
#[test]
492+
fn test_fen_string() {
493+
use crate::square::Square;
494+
let mut game = Game::new();
495+
assert_eq!(
496+
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
497+
format!("{}", game)
498+
);
499+
game.make_move(ChessMove::new(Square::E2, Square::E4, None));
500+
assert_eq!(
501+
"rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1",
502+
format!("{}", game)
503+
);
504+
game.make_move(ChessMove::new(Square::C7, Square::C5, None));
505+
assert_eq!(
506+
"rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2",
507+
format!("{}", game)
508+
);
509+
game.make_move(ChessMove::new(Square::G1, Square::F3, None));
510+
assert_eq!(
511+
"rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2",
512+
format!("{}", game)
513+
);
514+
}
515+
491516
#[test]
492517
pub fn test_can_declare_draw() {
493518
let game = fake_pgn_parser(

0 commit comments

Comments
 (0)