Board: add test for formatting

This commit is contained in:
Simon Gardling 2025-03-20 02:10:12 -04:00
parent 92b982cf35
commit 8b50273b43
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -96,9 +96,9 @@ impl fmt::Display for Board {
const SPACE_PADDING: &str = const_str::repeat!(" ", PADDING);
// Print numbers at top so the board can be read more easier
write!(f, "{} ", SPACE_PADDING)?;
write!(f, "{}", SPACE_PADDING)?;
for j in (0..Self::SIZE).rev() {
write!(f, "{:0PADDING$} ", j)?;
write!(f, " {:0PADDING$}", j)?;
}
writeln!(f)?;
@ -530,4 +530,31 @@ mod test {
assert_eq!(board.get((6, 0).into()), Some(Piece::Black), "\n{}", board);
}
#[test]
fn format_test() {
assert_eq!(
Board::new().starting_pos().to_string().as_str(),
" 7 6 5 4 3 2 1 0
-----------------
7| | | | | | | | |
-----------------
6| | | | | | | | |
-----------------
5| | | | | | | | |
-----------------
4| | | ||| | | |
-----------------
3| | | ||| | | |
-----------------
2| | | | | | | | |
-----------------
1| | | | | | | | |
-----------------
0| | | | | | | | |
-----------------
White Score: 2
Black Score: 2\n"
);
}
}