summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDon Stewart <dons@cse.unsw.edu.au>2007-04-30 08:59:46 +0200
committerDon Stewart <dons@cse.unsw.edu.au>2007-04-30 08:59:46 +0200
commitb98a875d5c2c2f7d561d6b2eae56f23d58672cf7 (patch)
treee1fb0c0c197c06c4eea67eccd22b9a5be4c217bb /tests
parent8238c35c211b4bc6258958918653d267787f8b47 (diff)
downloadmetatile-b98a875d5c2c2f7d561d6b2eae56f23d58672cf7.tar
metatile-b98a875d5c2c2f7d561d6b2eae56f23d58672cf7.zip
check we never generate invalid stack sets
darcs-hash:20070430065946-9c5c1-a63c2fa904ff1b915da40dfef6289ee935991992
Diffstat (limited to 'tests')
-rw-r--r--tests/Properties.hs19
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/Properties.hs b/tests/Properties.hs
index ba82fdc..4924e01 100644
--- a/tests/Properties.hs
+++ b/tests/Properties.hs
@@ -59,6 +59,22 @@ instance (Integral i, Integral j, Ord a, Arbitrary a) => Arbitrary (StackSet i j
return $ fromList (fromIntegral n,sc,ls)
coarbitrary = error "no coarbitrary for StackSet"
+-- Invariants:
+--
+-- * no element should ever appear more than once in a StackSet
+-- * the current index should always be valid
+--
+-- All operations must preserve this.
+--
+invariant (w :: T) = inBounds w && noDuplicates (concat $ M.elems (stacks w))
+ where
+ noDuplicates ws = nub ws == ws
+ inBounds x = current x >= 0 && current x < sz where sz = M.size (stacks x)
+
+-- test generator
+prop_invariant = invariant
+
+
-- empty StackSets have no windows in them
prop_empty n m = n > 0 && m > 0 ==> all null (M.elems (stacks x))
where x = empty n m :: T
@@ -295,7 +311,8 @@ main = do
n = 100
tests =
- [("empty is empty" , mytest prop_empty)
+ [("StackSet invariants", mytest prop_invariant)
+ ,("empty is empty" , mytest prop_empty)
,("empty / current" , mytest prop_empty_current)
,("member/push ", mytest prop_member1)