Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tearth committed Oct 30, 2024
1 parent a3bbdb7 commit f333a33
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
14 changes: 14 additions & 0 deletions tests/board_tests.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#[cfg(test)]
mod board_tests {
use inanis::engine::see;
use inanis::state::representation::Board;
use inanis::state::*;
use std::sync::Once;

static INIT: Once = Once::new();

macro_rules! is_square_attacked_tests {
($($name:ident: $fen:expr, $white_mask:expr, $black_mask:expr,)*) => {
$(
#[test]
fn $name() {
INIT.call_once(|| {
see::init();
movegen::init();
});

let board = Board::new_from_fen($fen).unwrap();

for color in ALL_COLORS {
Expand Down Expand Up @@ -44,6 +53,11 @@ mod board_tests {
$(
#[test]
fn $name() {
INIT.call_once(|| {
see::init();
movegen::init();
});

let board = Board::new_from_fen($fen).unwrap();
assert_eq!($expected_result, board.get_attacking_pieces($color, $square));
}
Expand Down
10 changes: 10 additions & 0 deletions tests/fen_tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#[cfg(test)]
mod fen_tests {
use inanis::engine::see;
use inanis::state::representation::Board;
use inanis::state::*;
use std::sync::Once;

static INIT: Once = Once::new();

macro_rules! fen_tests {
($($name:ident: $original_fen:expr,)*) => {
$(
#[test]
fn $name() {
INIT.call_once(|| {
see::init();
movegen::init();
});

assert_eq!($original_fen, Board::new_from_fen($original_fen).unwrap().to_fen());
}
)*
Expand Down
10 changes: 10 additions & 0 deletions tests/integrity_tests.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#[cfg(test)]
mod integrity_tests {
use inanis::engine::see;
use inanis::perft;
use inanis::state::representation::Board;
use inanis::state::*;
use std::sync::Once;

static INIT: Once = Once::new();

macro_rules! integrity_tests {
($($name:ident: $depth:expr, $fen:expr,)*) => {
$(
#[test]
fn $name() {
INIT.call_once(|| {
see::init();
movegen::init();
});

perft::normal::run($depth, &mut Board::new_from_fen($fen).unwrap(), true);
}
)*
Expand Down
10 changes: 10 additions & 0 deletions tests/perft_tests.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#[cfg(test)]
mod perft_tests {
use inanis::engine::see;
use inanis::perft;
use inanis::state::representation::Board;
use inanis::state::*;
use std::sync::Once;

static INIT: Once = Once::new();

macro_rules! perft_tests {
($($name:ident: $depth:expr, $fen:expr, $expected_leafs_count:expr,)*) => {
$(
#[test]
fn $name() {
INIT.call_once(|| {
see::init();
movegen::init();
});

assert_eq!($expected_leafs_count, perft::normal::run($depth, &mut Board::new_from_fen($fen).unwrap(), false).nodes);
}
)*
Expand Down
21 changes: 15 additions & 6 deletions tests/see_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@
mod see_tests {
use inanis::engine;
use inanis::engine::see;
use inanis::engine::see::*;
use inanis::state::representation::Board;
use inanis::state::*;
use std::mem::MaybeUninit;
use std::sync::Once;

static P: i16 = 100;
static N: i16 = 320;
static B: i16 = 320;
static R: i16 = 500;
static Q: i16 = 1100;
static INIT: Once = Once::new();

const P: i16 = SEE_PAWN_VALUE as i16 * 50;
const N: i16 = SEE_KNISHOP_VALUE as i16 * 50;
const B: i16 = SEE_KNISHOP_VALUE as i16 * 50;
const R: i16 = SEE_ROOK_VALUE as i16 * 50;
const Q: i16 = SEE_QUEEN_VALUE as i16 * 50;

macro_rules! see_tests {
($($name:ident: $fen:expr, $move:expr, $expected_result:expr, )*) => {
$(
#[test]
fn $name() {
let board = Board::new_from_fen($fen).unwrap();
INIT.call_once(|| {
see::init();
movegen::init();
});

let board = Board::new_from_fen($fen).unwrap();
let mut moves = [MaybeUninit::uninit(); engine::MAX_MOVES_COUNT];
let moves_count = board.get_all_moves(&mut moves, u64::MAX);

Expand Down

0 comments on commit f333a33

Please sign in to comment.