From: Ian Jackson Date: Sat, 10 Jul 2021 10:57:23 +0000 (+0100) Subject: jst-lower: Test cases exhaustive inputs autogenerator X-Git-Tag: otter-0.7.2~139 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=6a128bd116c3101348054d4f86d6ae224306b54d;p=otter.git jst-lower: Test cases exhaustive inputs autogenerator Signed-off-by: Ian Jackson --- diff --git a/jstest/jst-lower.rs b/jstest/jst-lower.rs index 3188afb4..7e2b3f21 100644 --- a/jstest/jst-lower.rs +++ b/jstest/jst-lower.rs @@ -295,6 +295,36 @@ impl TestsAccumulator { let already = self.tests.tests.insert(name.to_owned(), test); assert!(already.is_none(), "duplicate test {:?}", &name); } + + #[throws(Explode)] + pub fn add_exhaustive(&mut self, n: usize) { + let ids: Vec = (0..n).map( + |i| format!("{}.{}", i, n).try_into().unwrap() + ).collect_vec(); + + let pieces_configs = ids.iter().cloned().map(|id| { + [false,true].iter().cloned().map( move |bottom| { + StartPieceSpec { + id, + pinned: bottom, + moveable: PieceMoveable::Yes, + } + }) + }) + .multi_cartesian_product(); + + let target_configs = ids.iter().cloned() + .powerset(); + + for (ti, (pieces, targets)) in itertools::iproduct!( + pieces_configs, + target_configs + ).enumerate() { + if targets.is_empty() { continue } + let name = format!("exhaustive-{:02x}", ti); + self.add_test(&name,pieces, targets)?; + } + } } impl Tests { @@ -347,6 +377,8 @@ fn main() { ], vec![ "73.7", ])?; + + ta.add_exhaustive(2)?; let tests = ta.finalise()?;