A simple test for Container.addTwo
authorIustin Pop <iustin@google.com>
Wed, 27 May 2009 22:36:40 +0000 (23:36 +0100)
committerIustin Pop <iustin@google.com>
Mon, 1 Jun 2009 09:18:16 +0000 (11:18 +0200)
Ganeti/HTools/QC.hs
test.hs

index a133978..46fd430 100644 (file)
@@ -18,7 +18,7 @@ import qualified Ganeti.HTools.Utils as Utils
 
 -- copied from the introduction to quickcheck
 instance Arbitrary Char where
-    arbitrary     = choose ('\32', '\128')
+    arbitrary = choose ('\32', '\128')
 
 -- let's generate a random instance
 instance Arbitrary Instance.Instance where
@@ -81,6 +81,17 @@ prop_PeerMap_maxElem pmap =
     where _types = pmap::PeerMap.PeerMap
           puniq = PeerMap.accumArray const pmap
 
+-- Container tests
+
+prop_Container_addTwo cdata i1 i2 =
+    fn i1 i2 cont == fn i2 i1 cont &&
+       fn i1 i2 cont == fn i1 i2 (fn i1 i2 cont)
+    where _types = (cdata::[Int],
+                    i1::Int, i2::Int)
+          cont = foldl (\c x -> Container.add x x c) Container.empty cdata
+          fn x1 x2 = Container.addTwo x1 x1 x2 x2
+
+
 -- Simple instance tests, we only have setter/getters
 
 prop_Instance_setIdx inst idx =
diff --git a/test.hs b/test.hs
index 18a5ca6..14227e9 100644 (file)
--- a/test.hs
+++ b/test.hs
@@ -21,6 +21,9 @@ main = do
        , run prop_PeerMap_findMissing
        ]
 
+  runTests "Container" options
+       [ run prop_Container_addTwo ]
+
   runTests "Instance" options
        [ run prop_Instance_setIdx
        , run prop_Instance_setName