From: Michael Orlitzky Date: Mon, 17 Apr 2017 12:19:25 +0000 (-0400) Subject: Add reflexive/transitive property tests for the Cidr Ord instance. X-Git-Tag: 0.4.0~7 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=6087bef9274022251014f4ecbd166c35710480cd;p=hath.git Add reflexive/transitive property tests for the Cidr Ord instance. --- diff --git a/src/Cidr.hs b/src/Cidr.hs index e353406..d7f6246 100644 --- a/src/Cidr.hs +++ b/src/Cidr.hs @@ -303,7 +303,9 @@ cidr_properties = prop_all_cidrs_contain_themselves, prop_contains_proper_antisymmetric, prop_normalize_idempotent, - prop_normalize_preserves_equality ] + prop_normalize_preserves_equality, + prop_ord_instance_reflexive, + prop_ord_instance_transitive ] -- HUnit Tests @@ -548,7 +550,7 @@ prop_contains_proper_antisymmetric = -- Running "normalize" a second time shouldn't do anything. prop_normalize_idempotent :: TestTree prop_normalize_idempotent = - testProperty "The CIDR \"normalize\" function is idempotent " prop + testProperty "The CIDR \"normalize\" function is idempotent" prop where prop :: Cidr -> Bool prop cidr = (normalize cidr) == (normalize (normalize cidr)) @@ -556,7 +558,23 @@ prop_normalize_idempotent = -- Normalization should not affect equality of two CIDRs. prop_normalize_preserves_equality :: TestTree prop_normalize_preserves_equality = - testProperty "The CIDR \"normalize\" function preserves equality " prop + testProperty "The CIDR \"normalize\" function preserves equality" prop where prop :: Cidr -> Cidr -> Bool prop cidr1 cidr2 = (cidr1 == cidr2) == (normalize cidr1 == normalize cidr2) + +prop_ord_instance_reflexive :: TestTree +prop_ord_instance_reflexive = + testProperty "The CIDR order is reflexive" prop + where + prop :: Cidr -> Bool + prop cidr = cidr <= cidr + + +prop_ord_instance_transitive :: TestTree +prop_ord_instance_transitive = + testProperty "The CIDR order is transitive" prop + where + prop :: Cidr -> Cidr -> Cidr -> Property + prop cidr1 cidr2 cidr3 = + (cidr1 <= cidr2 && cidr2 <= cidr3) ==> cidr1 <= cidr3