From: Ian Jackson Date: Fri, 9 Jul 2021 13:42:55 +0000 (+0100) Subject: jstest: lower: check targets not deranged X-Git-Tag: otter-0.7.2~210 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=659a57bd93e433c9419293f9db23906bb2d71979;p=otter.git jstest: lower: check targets not deranged Signed-off-by: Ian Jackson --- 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 {