Clean up the liberty sharing test

This commit is contained in:
Savanni D'Gerinel 2023-04-14 09:06:41 -04:00
parent 037484e7b4
commit 3cd39af060
1 changed files with 68 additions and 41 deletions

View File

@ -173,9 +173,9 @@ impl std::fmt::Display for Board {
for row in 0..self.size.height {
for column in 0..self.size.width {
match self.stone(Coordinate { column, row }) {
None => write!(f, " . ")?,
Some(Color::Black) => write!(f, " X ")?,
Some(Color::White) => write!(f, " O ")?,
None => write!(f, " .")?,
Some(Color::Black) => write!(f, " X")?,
Some(Color::White) => write!(f, " O")?,
}
}
writeln!(f, "")?;
@ -310,6 +310,7 @@ mod test {
]
.into_iter(),
);
assert!(board.group(Coordinate { column: 18, row: 3 }).is_none());
assert_eq!(
board
.group(Coordinate { column: 3, row: 3 })
@ -347,15 +348,27 @@ mod test {
#[test]
fn stones_share_liberties() {
let board = Board::from_coordinates(
vec![
(Coordinate { column: 3, row: 3 }, Color::White),
(Coordinate { column: 3, row: 4 }, Color::White),
(Coordinate { column: 8, row: 3 }, Color::Black),
(Coordinate { column: 9, row: 3 }, Color::Black),
(Coordinate { column: 9, row: 4 }, Color::Black),
(Coordinate { column: 15, row: 3 }, Color::White),
(Coordinate { column: 15, row: 4 }, Color::White),
(Coordinate { column: 15, row: 5 }, Color::White),
(Coordinate { column: 14, row: 4 }, Color::White),
(Coordinate { column: 3, row: 8 }, Color::White),
(Coordinate { column: 3, row: 9 }, Color::White),
(Coordinate { column: 4, row: 9 }, Color::White),
(Coordinate { column: 3, row: 10 }, Color::Black),
]
.into_iter(),
);
let test_cases = vec![
(
Board::from_coordinates(
vec![
(Coordinate { column: 3, row: 3 }, Color::White),
(Coordinate { column: 3, row: 4 }, Color::White),
]
.into_iter(),
),
board.clone(),
Coordinate { column: 3, row: 4 },
Some(Group {
color: Color::White,
@ -369,21 +382,14 @@ mod test {
Some(6),
),
(
Board::from_coordinates(
vec![
(Coordinate { column: 3, row: 3 }, Color::White),
(Coordinate { column: 3, row: 4 }, Color::White),
(Coordinate { column: 4, row: 4 }, Color::White),
]
.into_iter(),
),
Coordinate { column: 3, row: 4 },
board.clone(),
Coordinate { column: 9, row: 3 },
Some(Group {
color: Color::White,
color: Color::Black,
coordinates: vec![
Coordinate { column: 3, row: 3 },
Coordinate { column: 3, row: 4 },
Coordinate { column: 4, row: 4 },
Coordinate { column: 8, row: 3 },
Coordinate { column: 9, row: 3 },
Coordinate { column: 9, row: 4 },
]
.into_iter()
.collect(),
@ -391,29 +397,36 @@ mod test {
Some(7),
),
(
Board::from_coordinates(
vec![
(Coordinate { column: 3, row: 3 }, Color::White),
(Coordinate { column: 3, row: 4 }, Color::White),
(Coordinate { column: 4, row: 4 }, Color::White),
(Coordinate { column: 3, row: 5 }, Color::White),
]
.into_iter(),
),
Coordinate { column: 3, row: 4 },
board.clone(),
Coordinate { column: 15, row: 4 },
Some(Group {
color: Color::White,
coordinates: vec![
Coordinate { column: 3, row: 3 },
Coordinate { column: 3, row: 4 },
Coordinate { column: 4, row: 4 },
Coordinate { column: 3, row: 5 },
Coordinate { column: 15, row: 3 },
Coordinate { column: 15, row: 4 },
Coordinate { column: 15, row: 5 },
Coordinate { column: 14, row: 4 },
]
.into_iter()
.collect(),
}),
Some(8),
),
(
board.clone(),
Coordinate { column: 3, row: 9 },
Some(Group {
color: Color::White,
coordinates: vec![
Coordinate { column: 3, row: 8 },
Coordinate { column: 3, row: 9 },
Coordinate { column: 4, row: 9 },
]
.into_iter()
.collect(),
}),
Some(6),
),
];
for (board, coordinate, group, liberties) in test_cases {
@ -427,10 +440,24 @@ mod test {
#[test]
fn opposing_stones_reduce_liberties() {
let mut board = Board::new();
board.place_stone(Coordinate { column: 3, row: 3 }, Color::White);
board.place_stone(Coordinate { column: 3, row: 4 }, Color::Black);
println!("{}", board);
let test_cases = vec![(
Board::from_coordinates(
vec![
(Coordinate { column: 3, row: 3 }, Color::White),
(Coordinate { column: 3, row: 4 }, Color::Black),
]
.into_iter(),
),
Coordinate { column: 3, row: 4 },
Some(6),
)];
println!("{}", test_cases[0].0);
for (board, coordinate, liberties) in test_cases {
assert_eq!(
board.group(coordinate).map(|g| board.liberties(&g)),
liberties
);
}
assert!(false);
}