chiark / gitweb /
jstest: lower: check targets not deranged
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 9 Jul 2021 13:42:55 +0000 (14:42 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 9 Jul 2021 13:42:55 +0000 (14:42 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
jstest/jst-lower.rs

index 0fc767f7985295282a00bcc87182d99e52f57677..57bcd6ac9ea5ce3de0271dc35f8b1afee3bf9997 100644 (file)
@@ -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 {