+ desc = "127.0.0.1/32 combines with itself recursively"
+ cidr1 = fromJust $ cidr_from_string "127.0.0.1/32"
+ expected_cidrs = [cidr1]
+ test_cidrs = [cidr1, cidr1, cidr1, cidr1, cidr1]
+
+
+test_combine_all3 :: Test
+test_combine_all3 =
+ testCase desc $
+ assertEqual
+ desc
+ expected_cidrs
+ (combine_all test_cidrs)
+ where
+ desc = "10.0.0.16, 10.0.0.17, 10.0.0.18, and "
+ ++ "10.0.0.19 get combined into 10.0.0.16/30"
+ cidr1 = fromJust $ cidr_from_string "10.0.0.16/32"
+ cidr2 = fromJust $ cidr_from_string "10.0.0.17/32"
+ cidr3 = fromJust $ cidr_from_string "10.0.0.18/32"
+ cidr4 = fromJust $ cidr_from_string "10.0.0.19/32"
+ expected_cidrs = [fromJust $ cidr_from_string "10.0.0.16/30"]
+ test_cidrs = [cidr1, cidr2, cidr3, cidr4]
+
+
+cidr_tests :: Test
+cidr_tests =
+ testGroup "CIDR Tests" [
+ test_min_host1,
+ test_max_host1,
+ test_equality1,
+ test_contains1,
+ test_contains2,
+ test_contains_proper1,
+ test_contains_proper2,
+ test_adjacent1,
+ test_adjacent2,
+ test_adjacent3,
+ test_adjacent4,
+ test_combine_contained1,
+ test_combine_contained2,
+ test_combine_all1,
+ test_combine_all2,
+ test_combine_all3 ]
+
+
+-- QuickCheck Tests
+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))
+
+cidr_properties :: Test
+cidr_properties =
+ testGroup "CIDR Properties" [
+ testProperty
+ "All CIDRs contain themselves"
+ prop_all_cidrs_contain_themselves,
+
+ testProperty
+ "contains_proper is intransitive"
+ prop_contains_proper_intransitive
+ ]