Annotated inequality operator for unit test properties
authorHelga Velroyen <helgav@google.com>
Mon, 22 Oct 2012 11:08:46 +0000 (13:08 +0200)
committerIustin Pop <iustin@google.com>
Mon, 22 Oct 2012 11:20:59 +0000 (13:20 +0200)
This includes:
 * The operator (/=?), which checks for inequality and prints
   an error message if it encounters equality. (Basically the
   negation of the (==?) operator).
 * Application of this operator in the test property
   prop_addPri_NoN1Fail.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

htest/Test/Ganeti/HTools/Node.hs
htest/Test/Ganeti/TestCommon.hs

index 3e4ea8b..2dd9c21 100644 (file)
@@ -138,9 +138,7 @@ prop_addPri_NoN1Fail =
   forAll genOnlineNode $ \node ->
   forAll (genInstanceSmallerThanNode node) $ \inst ->
   let inst' = inst { Instance.mem = Node.fMem node - Node.rMem node }
-  in case Node.addPri node inst' of
-    Bad Types.FailN1 -> False
-    _ -> True
+  in (Node.addPri node inst' /=? Bad Types.FailN1)
 
 -- | Check that an instance add with too high memory or disk will be
 -- rejected.
index d61cfb8..a5f7490 100644 (file)
@@ -80,6 +80,13 @@ maxOpCodes = 16
              show x ++ "' /= '" ++ show y ++ "'") (x == y)
 infix 3 ==?
 
+-- | Checks for inequality with proper annotation.
+(/=?) :: (Show a, Eq a) => a -> a -> Property
+(/=?) x y = printTestCase
+            ("Expected inequality, but got equality: '" ++
+             show x ++ "'.") (x /= y)
+infix 3 /=?
+
 -- | Show a message and fail the test.
 failTest :: String -> Property
 failTest msg = printTestCase msg False