-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
875 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,37 @@ | ||
#[cfg(feature = "variant")] | ||
#[test] | ||
fn white_insufficient_material_in_horde() { | ||
use std::{ | ||
fs::File, | ||
io::{prelude::*, BufReader}, | ||
}; | ||
use serde::Deserialize; | ||
use serde_with::{serde_as, DisplayFromStr}; | ||
use shakmaty::{fen::Fen, variant::Horde, CastlingMode, Color, Position}; | ||
|
||
use shakmaty::{fen::Fen, variant::Horde, CastlingMode, Color, FromSetup, Position}; | ||
#[serde_as] | ||
#[derive(Deserialize)] | ||
struct Record { | ||
#[serde_as(as = "DisplayFromStr")] | ||
fen: Fen, | ||
white_has_insufficient_material: bool, | ||
comment: String, | ||
} | ||
|
||
let mut reader = | ||
csv::Reader::from_path("tests/horde_insufficient_material.csv").expect("reader"); | ||
|
||
fn assert_white_insufficient_material_in_horde<P>( | ||
fen: &str, | ||
expected_outcome: bool, | ||
comment: &str, | ||
) where | ||
P: Position + FromSetup, | ||
{ | ||
let pos: P = fen | ||
.parse::<Fen>() | ||
.expect("valid fen") | ||
for (i, record) in reader.deserialize().enumerate() { | ||
let record: Record = record.expect("record"); | ||
let pos: Horde = record | ||
.fen | ||
.clone() | ||
.into_position(CastlingMode::Chess960) | ||
.expect("valid position"); | ||
|
||
let has_insufficient_material = pos.has_insufficient_material(Color::White); | ||
|
||
assert_eq!( | ||
has_insufficient_material, | ||
expected_outcome, | ||
" | ||
\n | ||
{:?}\n | ||
{:?} | ||
{:?}\n | ||
computed_outcome={:?} | ||
expected_outcome={:?}\n\n", | ||
comment, | ||
pos.board(), | ||
fen, | ||
has_insufficient_material, | ||
expected_outcome | ||
); | ||
} | ||
|
||
let file = | ||
File::open("tests/horde_insufficient_material.csv").expect("failed to open test suite"); | ||
let reader = BufReader::new(file); | ||
|
||
for line in reader.lines().map(|l| l.unwrap()) { | ||
let mut columns = line.split(','); | ||
|
||
assert_white_insufficient_material_in_horde::<Horde>( | ||
columns.next().unwrap(), | ||
columns.next().unwrap() == "true", | ||
columns.next().unwrap(), | ||
pos.has_insufficient_material(Color::White), | ||
record.white_has_insufficient_material, | ||
"{} with comment {:?} in line {}", | ||
record.fen, | ||
record.comment, | ||
i + 1 | ||
); | ||
} | ||
} |
Oops, something went wrong.