]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/Cidr.hs
Added Arbitrary instance definitions for the main data types.
[hath.git] / src / Cidr.hs
index c0c639a76e8ec1c72281145e10bb3fcfa4287f20..7bb3ac2c41229b286f67f39a8ce58c24274171b7 100644 (file)
@@ -7,6 +7,7 @@ module Cidr
 
 import Data.List (nubBy)
 import Test.HUnit
+import Test.QuickCheck
 
 import IPv4Address
 import ListUtils
@@ -25,6 +26,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