diff --git a/crates/coremem/src/sim/spirv/mod.rs b/crates/coremem/src/sim/spirv/mod.rs index e87e8af..7a501ee 100644 --- a/crates/coremem/src/sim/spirv/mod.rs +++ b/crates/coremem/src/sim/spirv/mod.rs @@ -444,6 +444,41 @@ mod test { test_same::(0x1234, 100, 10, Index::new(24, 20, 44)); } + fn test_same_conductor> + Send + Sync>( + seed: u64, step_iters: u64, steps_per_iter: u32, size: Index + ) { + use rand::{Rng as _, SeedableRng as _}; + let mut rng = rand::rngs::StdRng::seed_from_u64(seed); + let mut ref_state = SimState::new(size, 1e-3); + let mut dut_state = SpirvSim::, B>::new(size, 1e-3); + + for z in 0..size.z() { + for y in 0..size.y() { + for x in 0..size.x() { + let cond = Vec3::new( + rng.gen_range(0.0..1e6), + rng.gen_range(0.0..1e6), + rng.gen_range(0.0..1e6), + ); + ref_state.put_material(Index::new(x, y, z), AnisomorphicConductor::new(cond.cast())); + dut_state.put_material(Index::new(x, y, z), AnisomorphicConductor::new(cond.cast())); + } + } + } + + ref_state.apply_stimulus(&RngStimulus::new(seed)); + dut_state.apply_stimulus(&RngStimulus::new(seed)); + + test_same_explicit(ref_state, dut_state, step_iters, steps_per_iter); + } + + pub fn do_conductor_1_step> + Send + Sync>() { + test_same_conductor::(0x1234, 1, 1, Index::new(4, 4, 4)); + } + + pub fn do_conductor_many_steps_larger> + Send + Sync>() { + test_same_conductor::(0x1234, 100, 10, Index::new(96, 16, 8)); + } } macro_rules! test_backend { @@ -504,6 +539,14 @@ mod test { fn same_100_steps_of_10() { do_same_100_steps_of_10::<$backend>(); } + #[test] + fn conductor_1_step() { + do_conductor_1_step::<$backend>(); + } + #[test] + fn conductor_many_steps_larger() { + do_conductor_many_steps_larger::<$backend>(); + } } } } @@ -819,44 +862,6 @@ mod test { } } - fn test_same_conductor(seed: u64, step_iters: u64, steps_per_iter: u32, size: Index) { - use rand::{Rng as _, SeedableRng as _}; - let mut rng = rand::rngs::StdRng::seed_from_u64(seed); - let mut ref_state = SimState::new(size, 1e-3); - let mut dut_state: SpirvSim = SpirvSim::new(size, 1e-3); - - for z in 0..size.z() { - for y in 0..size.y() { - for x in 0..size.x() { - let cond = Vec3::new( - rng.gen_range(0.0..1e6), - rng.gen_range(0.0..1e6), - rng.gen_range(0.0..1e6), - ); - ref_state.put_material(Index::new(x, y, z), AnisomorphicConductor::new(cond.cast())); - dut_state.put_material(Index::new(x, y, z), AnisomorphicConductor::new(cond.cast())); - } - } - } - - ref_state.apply_stimulus(&RngStimulus::new(seed)); - dut_state.apply_stimulus(&RngStimulus::new(seed)); - - test_same_explicit(ref_state, dut_state, step_iters, steps_per_iter); - } - - // TODO: port the rest of these tests to the test_backend macro - - #[test] - fn conductor_1_step() { - test_same_conductor(0x1234, 1, 1, Index::new(4, 4, 4)); - } - - #[test] - fn conductor_many_steps_larger() { - test_same_conductor(0x1234, 100, 10, Index::new(96, 16, 8)); - } - fn test_same_mb_ferromagnet(seed: u64, step_iters: u64, steps_per_iter: u32, size: Index) { use rand::{Rng as _, SeedableRng as _}; let mut rng = rand::rngs::StdRng::seed_from_u64(seed); @@ -895,6 +900,8 @@ mod test { test_same_explicit(ref_state, dut_state, step_iters, steps_per_iter); } + // TODO: port the rest of these tests to the test_backend macro + #[test] fn mb_ferromagnet_1_step() { test_same_mb_ferromagnet(0x1234, 1, 1, Index::new(4, 4, 4));