From: Michael Orlitzky Date: Fri, 14 May 2010 05:59:06 +0000 (-0400) Subject: Added the prop_contains_proper_intransitive QuickCheck property, and fixed the defini... X-Git-Tag: 0.0.1~40 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=a23ed449c784cdf81501c696bec10b1fbaeefc5f;p=hath.git Added the prop_contains_proper_intransitive QuickCheck property, and fixed the definition of contains_proper when it found a bug. --- diff --git a/src/Cidr.hs b/src/Cidr.hs index 5c9fefd..94de123 100644 --- a/src/Cidr.hs +++ b/src/Cidr.hs @@ -3,7 +3,10 @@ module Cidr cidr_from_string, cidr_tests, combine_all, - prop_all_cidrs_contain_themselves + contains, + contains_proper, + prop_all_cidrs_contain_themselves, + prop_contains_proper_intransitive ) where import Data.List (nubBy) @@ -124,7 +127,7 @@ contains (Cidr addr1 mbits1) (Cidr addr2 mbits2) contains_proper :: Cidr -> Cidr -> Bool contains_proper cidr1 cidr2 = - (cidr1 `contains` cidr2) && (not (cidr1 == cidr2)) + (cidr1 `contains` cidr2) && (not (cidr2 `contains` cidr1)) -- A CIDR range is redundant (with respect to the given list) if @@ -296,3 +299,10 @@ cidr_tests = [ test_equality1, 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)) diff --git a/test/TestSuite.hs b/test/TestSuite.hs index 3538d21..4450f1d 100644 --- a/test/TestSuite.hs +++ b/test/TestSuite.hs @@ -2,7 +2,8 @@ import Test.HUnit import Test.QuickCheck.Batch import Cidr (cidr_tests, - prop_all_cidrs_contain_themselves) + prop_all_cidrs_contain_themselves, + prop_contains_proper_intransitive) import IPv4Address (ipv4address_tests) import Maskable (maskable_tests) @@ -29,4 +30,5 @@ main = do putStrLn "QuickCheck" putStrLn "----------" - runTests "Cidr" options [ run prop_all_cidrs_contain_themselves ] + runTests "Cidr" options [ run prop_all_cidrs_contain_themselves, + run prop_contains_proper_intransitive]