Use 'ChessBoard::validate' in tests

This makes the test more explicit and exact in what they're testing.
This commit is contained in:
Bruno BELANYI 2024-04-01 20:42:28 +01:00
parent 8173fa2ccd
commit 12909377e4

View file

@ -530,7 +530,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::OverlappingPieces,
);
} }
#[test] #[test]
@ -558,7 +561,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::OverlappingColors,
);
} }
#[test] #[test]
@ -586,7 +592,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::ErroneousCombinedOccupancy,
);
} }
#[test] #[test]
@ -614,7 +623,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::ErroneousCombinedOccupancy,
);
} }
#[test] #[test]
@ -642,7 +654,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::TooManyPieces,
);
} }
#[test] #[test]
@ -670,7 +685,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::InvalidCastlingRights,
);
} }
#[test] #[test]
@ -706,7 +724,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::InvalidCastlingRights,
);
} }
#[test] #[test]
@ -734,7 +755,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::NeighbouringKings,
);
} }
#[test] #[test]
@ -762,7 +786,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::OpponentInCheck,
);
} }
#[test] #[test]
@ -790,7 +817,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::InvalidPawnPosition,
);
} }
#[test] #[test]
@ -829,7 +859,10 @@ mod test {
total_plies: 0, total_plies: 0,
side: Color::White, side: Color::White,
}; };
assert!(!position.is_valid()); assert_eq!(
position.validate().err().unwrap(),
InvalidError::TooManyPieces,
);
} }
#[test] #[test]