X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FCidr.hs;h=5c9fefd66e6714c5a6eeeb62718ccffd668345b8;hb=0be56eaa64ab03adf3aa1f3f3c14a191c09045c8;hp=c0c639a76e8ec1c72281145e10bb3fcfa4287f20;hpb=a626afee0e8a4d5a8e1b9a22c150073be6a00cc3;p=hath.git diff --git a/src/Cidr.hs b/src/Cidr.hs index c0c639a..5c9fefd 100644 --- a/src/Cidr.hs +++ b/src/Cidr.hs @@ -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 +