[board] A small set of unit tests for Zobrist hashes on Board
A few tests to ensure the zobrist hash changes when changes are made to the Board. This set isn't exhaustive.
This commit is contained in:
parent
651c982ead
commit
1686eeb35a
1 changed files with 52 additions and 1 deletions
|
@ -325,7 +325,7 @@ impl Board {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_board;
|
use crate::test_board;
|
||||||
use chessfriend_core::piece;
|
use chessfriend_core::{piece, random::RandomNumberGenerator};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_piece_on_square() {
|
fn get_piece_on_square() {
|
||||||
|
@ -335,4 +335,55 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(board.get_piece(Square::F7), Some(piece!(Black Bishop)));
|
assert_eq!(board.get_piece(Square::F7), Some(piece!(Black Bishop)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Zobrist Hashing
|
||||||
|
|
||||||
|
fn test_state() -> ZobristState {
|
||||||
|
let mut rng = RandomNumberGenerator::default();
|
||||||
|
ZobristState::new(&mut rng)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zobrist_hash_set_for_empty_board() {
|
||||||
|
let state = Arc::new(test_state());
|
||||||
|
let board = Board::empty(Some(state.clone()));
|
||||||
|
let hash = board.zobrist_hash();
|
||||||
|
assert_eq!(hash, Some(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zobrist_hash_set_for_starting_position_board() {
|
||||||
|
let state = Arc::new(test_state());
|
||||||
|
let board = Board::starting(Some(state.clone()));
|
||||||
|
let hash = board.zobrist_hash();
|
||||||
|
assert!(hash.is_some());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zobrist_hash_updated_when_changing_active_color() {
|
||||||
|
let state = Arc::new(test_state());
|
||||||
|
|
||||||
|
let mut board = Board::empty(Some(state.clone()));
|
||||||
|
board.set_active_color(Color::Black);
|
||||||
|
|
||||||
|
// Just verify that the value is real and has changed. The actual value
|
||||||
|
// computation is covered by the tests in zobrist.rs.
|
||||||
|
let hash = board.zobrist_hash();
|
||||||
|
assert!(hash.is_some());
|
||||||
|
assert_ne!(hash, Some(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zobrist_hash_updated_when_changing_en_passant_target() {
|
||||||
|
let state = Arc::new(test_state());
|
||||||
|
|
||||||
|
let mut board = Board::empty(Some(state.clone()));
|
||||||
|
board.set_en_passant_target(Square::C3);
|
||||||
|
|
||||||
|
// Just verify that the value is real and has changed. The actual value
|
||||||
|
// computation is covered by the tests in zobrist.rs.
|
||||||
|
let hash = board.zobrist_hash();
|
||||||
|
assert!(hash.is_some());
|
||||||
|
assert_ne!(hash, Some(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue