Skip to content

Commit

Permalink
Merge branch '0.26.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Feb 22, 2024
2 parents 20c54be + dd9ec24 commit c44e6aa
Show file tree
Hide file tree
Showing 5 changed files with 875 additions and 45 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ arrayvec = { version = "0.7", default-features = false }
nohash-hasher = { version = "0.2", optional = true }

[dev-dependencies]
csv = "1"
iai = { version = "0.1", git = "https://github.com/sigaloid/iai", rev = "d56a5971f6d5556cd9e9b92e7e0f753c9ce9cdc7" }
serde = { version = "1", features = ["derive"] }
serde_with = "3"

[package.metadata.docs.rs]
all-features = true
Expand Down
1 change: 1 addition & 0 deletions tests/horde_insufficient_material.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fen,white_has_insufficient_material,comment
8/8/4r3/2b5/8/8/7q/7k b - - 0 1,true,white=0
8/8/8/8/8/8/7b/5Q1k b - - 0 1,true,white=Q
8/8/8/8/8/2Q5/q7/kq6 b - - 0 1,true,white=Q
Expand Down
70 changes: 25 additions & 45 deletions tests/horde_insufficient_material.rs
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
);
}
}
Loading

0 comments on commit c44e6aa

Please sign in to comment.