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

@ -310,6 +310,7 @@ mod test {
] ]
.into_iter(), .into_iter(),
); );
assert!(board.group(Coordinate { column: 18, row: 3 }).is_none());
assert_eq!( assert_eq!(
board board
.group(Coordinate { column: 3, row: 3 }) .group(Coordinate { column: 3, row: 3 })
@ -347,15 +348,27 @@ mod test {
#[test] #[test]
fn stones_share_liberties() { fn stones_share_liberties() {
let test_cases = vec![ let board = Board::from_coordinates(
(
Board::from_coordinates(
vec![ vec![
(Coordinate { column: 3, row: 3 }, Color::White), (Coordinate { column: 3, row: 3 }, Color::White),
(Coordinate { column: 3, row: 4 }, 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(), .into_iter(),
), );
let test_cases = vec![
(
board.clone(),
Coordinate { column: 3, row: 4 }, Coordinate { column: 3, row: 4 },
Some(Group { Some(Group {
color: Color::White, color: Color::White,
@ -369,21 +382,14 @@ mod test {
Some(6), Some(6),
), ),
( (
Board::from_coordinates( board.clone(),
vec![ Coordinate { column: 9, row: 3 },
(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 },
Some(Group { Some(Group {
color: Color::White, color: Color::Black,
coordinates: vec![ coordinates: vec![
Coordinate { column: 3, row: 3 }, Coordinate { column: 8, row: 3 },
Coordinate { column: 3, row: 4 }, Coordinate { column: 9, row: 3 },
Coordinate { column: 4, row: 4 }, Coordinate { column: 9, row: 4 },
] ]
.into_iter() .into_iter()
.collect(), .collect(),
@ -391,29 +397,36 @@ mod test {
Some(7), Some(7),
), ),
( (
Board::from_coordinates( board.clone(),
vec![ Coordinate { column: 15, row: 4 },
(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 },
Some(Group { Some(Group {
color: Color::White, color: Color::White,
coordinates: vec![ coordinates: vec![
Coordinate { column: 3, row: 3 }, Coordinate { column: 15, row: 3 },
Coordinate { column: 3, row: 4 }, Coordinate { column: 15, row: 4 },
Coordinate { column: 4, row: 4 }, Coordinate { column: 15, row: 5 },
Coordinate { column: 3, row: 5 }, Coordinate { column: 14, row: 4 },
] ]
.into_iter() .into_iter()
.collect(), .collect(),
}), }),
Some(8), 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 { for (board, coordinate, group, liberties) in test_cases {
@ -427,10 +440,24 @@ mod test {
#[test] #[test]
fn opposing_stones_reduce_liberties() { fn opposing_stones_reduce_liberties() {
let mut board = Board::new(); let test_cases = vec![(
board.place_stone(Coordinate { column: 3, row: 3 }, Color::White); Board::from_coordinates(
board.place_stone(Coordinate { column: 3, row: 4 }, Color::Black); vec![
println!("{}", board); (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); assert!(false);
} }