Skip to content

Commit

Permalink
Add test to enforce FEN strings for Game
Browse files Browse the repository at this point in the history
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
  • Loading branch information
WalterSmuts committed Jun 7, 2021
1 parent ccc1afe commit 4d6ae78
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,36 @@ pub fn fake_pgn_parser(moves: &str) -> Game {
})
}

#[test]
fn test_fen_string() {
use crate::square::Square;
let mut game = Game::new();
assert_eq!(
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
format!("{}", game)
);
game.make_move(ChessMove::new(Square::E2, Square::E4, None));
assert_eq!(
"rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1",
format!("{}", game)
);
game.make_move(ChessMove::new(Square::C7, Square::C5, None));
assert_eq!(
"rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2",
format!("{}", game)
);
game.make_move(ChessMove::new(Square::G1, Square::F3, None));
let final_serialized_game = format!("{}", game);
assert_eq!(
"rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2",
final_serialized_game
);
assert_eq!(
final_serialized_game,
format!("{}", Game::from_str(&final_serialized_game).unwrap()),
);
}

#[test]
pub fn test_can_declare_draw() {
let game = fake_pgn_parser(
Expand Down

0 comments on commit 4d6ae78

Please sign in to comment.