From 659a57bd93e433c9419293f9db23906bb2d71979 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 9 Jul 2021 14:42:55 +0100 Subject: [PATCH] jstest: lower: check targets not deranged Signed-off-by: Ian Jackson --- jstest/jst-lower.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/jstest/jst-lower.rs b/jstest/jst-lower.rs index 0fc767f7..57bcd6ac 100644 --- a/jstest/jst-lower.rs +++ b/jstest/jst-lower.rs @@ -72,6 +72,29 @@ impl Test { } // non-bottom targets are in same stacking order as before + { + #[derive(Debug,Ord,PartialOrd,Eq,PartialEq)] + struct Nbt<'o,'n> { + old_z: &'o ZCoord, + new_z: &'n ZCoord, + id: VisiblePieceId, + } + let mut nbts = self.targets.iter() + .map(|&id| { + let old_z = &self.pieces[&id].z; + let new_z = updated.get(&id).unwrap_or(old_z); + Nbt { new_z, old_z, id } + }) + .collect_vec(); + nbts.sort(); + nbts.iter().fold1( |nbt0, nbt1| { + assert!( nbt0.new_z < nbt1.new_z, + "{:?} {:?} {:?} {:#?}", &self.name, nbt0, nbt1, + &nbts); + nbt1 + }); + } + // no bottom are newly above non-bottom // no non-bottom non-targets moved // z coords in updates all decrease @@ -82,6 +105,18 @@ impl Test { } } +impl StartPiece { + pub fn bottom(&self) -> bool { + use PieceMoveable::*; + match (self.pinned, self.moveable) { + (true , _ ) => true, + (false, Yes) => false, + (false, No ) => true, + (_, IfWresting) => panic!(), + } + } +} + impl TestsAccumulator { #[throws(Explode)] pub fn new(opts: &Opts) -> Self { -- 2.30.2