]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/Cidr.hs
Added a QuickCheck property verifying that all Cidrs contain themselves.
[hath.git] / src / Cidr.hs
index c0c639a76e8ec1c72281145e10bb3fcfa4287f20..5c9fefd66e6714c5a6eeeb62718ccffd668345b8 100644 (file)
@@ -2,11 +2,13 @@ module Cidr
 ( Cidr(..),
   cidr_from_string,
   cidr_tests,
-  combine_all
+  combine_all,
+  prop_all_cidrs_contain_themselves
 ) where
 
 import Data.List (nubBy)
 import Test.HUnit
+import Test.QuickCheck
 
 import IPv4Address
 import ListUtils
@@ -25,6 +27,15 @@ instance Show Cidr where
     show cidr = (show (ipv4address cidr)) ++ "/" ++ (show (maskbits cidr))
 
 
+instance Arbitrary Cidr where
+    arbitrary = do
+      ipv4 <- arbitrary :: Gen IPv4Address
+      mask <- arbitrary :: Gen Maskbits
+      return (Cidr ipv4 mask)
+
+    coarbitrary _ = variant 0
+
+
 -- Two CIDR ranges are equivalent if they have the same network bits
 -- and the masks are the same.
 equivalent :: Cidr -> Cidr -> Bool
@@ -279,3 +290,9 @@ cidr_tests = [ test_equality1,
                test_combine_contained1,
                test_combine_contained2
              ]
+
+
+-- QuickCheck Tests
+prop_all_cidrs_contain_themselves :: Cidr -> Bool
+prop_all_cidrs_contain_themselves cidr1 = cidr1 `contains` cidr1
+