[Added tests for associativity, commutativity and idempotence. Nils Anders Danielsson **20050531203429] { hunk ./Test/ChasingBottoms/TestUtilities.hs 9 + , isAssociative + , isCommutative + , isIdempotent hunk ./Test/ChasingBottoms/TestUtilities.hs 78 +-- | Test for associativity. + +isAssociative + :: Show a + => Gen (a, a, a) + -- ^ Generator for arbitrary elements, possibly related in some + -- way to make the test more meaningful. + -> (a -> a -> Bool) + -- ^ Equality test. + -> (a -> a -> a) + -- ^ The operation. + -> Property +isAssociative triple (==.) (+.) = + forAll triple $ \(x, y, z) -> + ((x +. y) +. z) ==. (x +. (y +. z)) + +-- | Test for commutativity. + +isCommutative + :: Show a + => Gen (a, a) + -- ^ Generator for arbitrary elements, possibly related in some + -- way to make the test more meaningful. + -> (b -> b -> Bool) + -- ^ Equality test. + -> (a -> a -> b) + -- ^ The operation. + -> Property +isCommutative pair (==.) (+.) = + forAll pair $ \(x, y) -> + (x +. y) ==. (y +. x) + +-- | Test for idempotence. + +isIdempotent + :: Show a + => Gen a + -- ^ Generator for arbitrary element. + -> (a -> a -> Bool) + -- ^ Equality test. + -> (a -> a -> a) + -- ^ The operation. + -> Property +isIdempotent element (==.) (+.) = + forAll element $ \x -> + (x +. x) ==. x + }