X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FIPv4Address.hs;h=55602aa8a9616197d6ecf038e6b071eec87e79d3;hb=a23ed449c784cdf81501c696bec10b1fbaeefc5f;hp=29afa5f3dd2c34264a98b39c250d93b5160db6af;hpb=d1e7f72b70cfe4c1a5c5eb6e7773888506833131;p=hath.git diff --git a/src/IPv4Address.hs b/src/IPv4Address.hs index 29afa5f..55602aa 100644 --- a/src/IPv4Address.hs +++ b/src/IPv4Address.hs @@ -18,6 +18,7 @@ module IPv4Address ) where import Test.HUnit +import Test.QuickCheck import qualified Bit as B import Maskbits @@ -43,6 +44,18 @@ instance Show IPv4Address where oct4 = (octet4 addr) +instance Arbitrary IPv4Address where + arbitrary = do + oct1 <- arbitrary :: Gen Octet + oct2 <- arbitrary :: Gen Octet + oct3 <- arbitrary :: Gen Octet + oct4 <- arbitrary :: Gen Octet + return (IPv4Address oct1 oct2 oct3 oct4) + + coarbitrary _ = variant 0 + + + -- We don't export our constructor so this function is the only -- way to construct an address from octets. As a result, we can -- return IPv4Address.None in response to being passed one of more @@ -355,14 +368,16 @@ mk_testaddr a b c d = oct4 = octet_from_int d +test_most_sig_bit_different1 :: Test test_most_sig_bit_different1 = TestCase $ assertEqual "10.1.1.0 and 10.1.0.0 differ in bit 24" TwentyFour (most_sig_bit_different (mk_testaddr 10 1 1 0) (mk_testaddr 10 1 0 0)) +test_most_sig_bit_different2 :: Test test_most_sig_bit_different2 = TestCase $ assertEqual "10.1.2.0 and 10.1.1.0 differ in bit 23" TwentyThree (most_sig_bit_different (mk_testaddr 10 1 2 0) (mk_testaddr 10 1 1 0)) - +ipv4address_tests :: [Test] ipv4address_tests = [ test_most_sig_bit_different1, test_most_sig_bit_different2 ]