]> gitweb.michael.orlitzky.com - hath.git/commitdiff
Added the prop_contains_proper_intransitive QuickCheck property, and fixed the defini...
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 14 May 2010 05:59:06 +0000 (01:59 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 14 May 2010 05:59:06 +0000 (01:59 -0400)
src/Cidr.hs
test/TestSuite.hs

index 5c9fefd66e6714c5a6eeeb62718ccffd668345b8..94de1234c4ae9616f7b9d351a5b9a0f6ba434bc7 100644 (file)
@@ -3,7 +3,10 @@ module Cidr
   cidr_from_string,
   cidr_tests,
   combine_all,
-  prop_all_cidrs_contain_themselves
+  contains,
+  contains_proper,
+  prop_all_cidrs_contain_themselves,
+  prop_contains_proper_intransitive
 ) where
 
 import Data.List (nubBy)
@@ -124,7 +127,7 @@ contains (Cidr addr1 mbits1) (Cidr addr2 mbits2)
 
 contains_proper :: Cidr -> Cidr -> Bool
 contains_proper cidr1 cidr2 =
-    (cidr1 `contains` cidr2) && (not (cidr1 == cidr2))
+    (cidr1 `contains` cidr2) && (not (cidr2 `contains` cidr1))
 
 
 -- A CIDR range is redundant (with respect to the given list) if
@@ -296,3 +299,10 @@ cidr_tests = [ test_equality1,
 prop_all_cidrs_contain_themselves :: Cidr -> Bool
 prop_all_cidrs_contain_themselves cidr1 = cidr1 `contains` cidr1
 
+
+-- If cidr1 properly contains cidr2, then by definition cidr2
+-- does not properly contain cidr1.
+prop_contains_proper_intransitive :: Cidr -> Cidr -> Property
+prop_contains_proper_intransitive cidr1 cidr2 =
+    (cidr1 `contains_proper` cidr2) ==>
+      (not (cidr2 `contains_proper` cidr1))
index 3538d21141455e8d6938cdae4ff59fc3f497be43..4450f1d34001afaf731f17159492c09e6501c7b1 100644 (file)
@@ -2,7 +2,8 @@ import Test.HUnit
 import Test.QuickCheck.Batch
 
 import Cidr (cidr_tests,
-             prop_all_cidrs_contain_themselves)
+             prop_all_cidrs_contain_themselves,
+             prop_contains_proper_intransitive)
 
 import IPv4Address (ipv4address_tests)
 import Maskable (maskable_tests)
@@ -29,4 +30,5 @@ main = do
 
   putStrLn "QuickCheck"
   putStrLn "----------"
-  runTests "Cidr" options [ run prop_all_cidrs_contain_themselves ]
+  runTests "Cidr" options [ run prop_all_cidrs_contain_themselves,
+                            run prop_contains_proper_intransitive]