Move position::tests → testing
Expand information printed in assert_move_list
This commit is contained in:
parent
9b7bf3a212
commit
36db46ac18
3 changed files with 59 additions and 35 deletions
58
position/src/testing.rs
Normal file
58
position/src/testing.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use crate::MakeMoveError;
|
||||
use chessfriend_moves::{BuildMoveError, BuildMoveResult, Move};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_move_list {
|
||||
($generated:expr, $expected:expr, $position:expr) => {
|
||||
assert_eq!(
|
||||
$generated,
|
||||
$expected,
|
||||
"\n\tMatching: {:?}\n\tGenerated, not expected: {:?}\n\tExpected, not generated: {:?}",
|
||||
$generated
|
||||
.intersection(&$expected)
|
||||
.map(|mv| format!("{}", mv))
|
||||
.collect::<Vec<String>>(),
|
||||
$generated
|
||||
.difference(&$expected)
|
||||
.map(|mv| format!("{}", mv))
|
||||
.collect::<Vec<String>>(),
|
||||
$expected
|
||||
.difference(&$generated)
|
||||
.map(|mv| format!("{}", mv))
|
||||
.collect::<Vec<String>>(),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! formatted_move_list {
|
||||
($move_list:expr, $position:expr) => {
|
||||
$move_list
|
||||
.iter()
|
||||
.map(|mv| format!("{}", mv))
|
||||
.collect::<Vec<String>>()
|
||||
};
|
||||
}
|
||||
|
||||
pub type TestResult = Result<(), TestError>;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum TestError {
|
||||
BuildMove(BuildMoveError),
|
||||
MakeMove(MakeMoveError),
|
||||
NoLegalMoves,
|
||||
}
|
||||
|
||||
impl From<BuildMoveError> for TestError {
|
||||
fn from(value: BuildMoveError) -> Self {
|
||||
TestError::BuildMove(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MakeMoveError> for TestError {
|
||||
fn from(value: MakeMoveError) -> Self {
|
||||
TestError::MakeMove(value)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue