cleanup test + ensure chain validity

This commit is contained in:
Simon Gardling 2025-02-18 22:53:13 -05:00
parent 6bda402a12
commit 45224bf6c2
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
2 changed files with 12 additions and 5 deletions

View File

@ -1,8 +1,6 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use std::time::Duration;
// use crate::future_move::FutureMove;
use othello::{board::Board, future_moves::FutureMoves, piece::Piece};
use std::time::Duration;
fn extend_layers_test(depth: usize, expire: usize) {
let mut fut = FutureMoves::new(Piece::Black, depth, expire);
@ -15,10 +13,10 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group(format!("extend_layers (expire {})", EXPIRE));
group.measurement_time(Duration::from_secs(10));
for (depth, expire) in (2..6).zip([EXPIRE].iter().cycle()) {
for (depth, expire) in (2..6).zip([EXPIRE].into_iter().cycle()) {
group.throughput(Throughput::Elements(depth as u64));
group.bench_with_input(BenchmarkId::from_parameter(depth), &depth, |b, depth| {
b.iter(|| extend_layers_test(*depth, *expire));
b.iter(|| extend_layers_test(*depth, expire));
});
}
group.finish();

View File

@ -53,6 +53,15 @@ fn gen_adj_lookup() -> PosMap<ChainCollection> {
// handle diagonals
chains.extend(diag_raw(i_chain, j_chain).map(Iterator::collect));
// make sure all chains are in the proper range so we can ignore bounds checking later
assert!(
chains.iter().all(|x| x.iter().all(
|(i, j)| (0..BOARD_SIZE).contains(i) && (0..BOARD_SIZE).contains(j)
)),
"chains go out-of-bounds"
);
chains
})
.collect()