From c725515c82d7475a2423042349a9cd4a47471974 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 9 May 2010 15:22:48 -0400 Subject: [PATCH] Add two HUnit tests for IPv4Address. --- src/IPv4Address.hs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/IPv4Address.hs b/src/IPv4Address.hs index 31ad7bd..c79472c 100644 --- a/src/IPv4Address.hs +++ b/src/IPv4Address.hs @@ -1,5 +1,6 @@ module IPv4Address ( ipv4address_from_octets, + ipv4address_tests, IPv4Address(None), max_octet1, max_octet2, @@ -14,8 +15,9 @@ module IPv4Address octet2, octet3, octet4 -) - where +) where + +import Test.HUnit import qualified Bit as B import Maskbits @@ -339,3 +341,28 @@ most_sig_bit_different addr1 addr2 oct2b = (octet2 addr2) oct3b = (octet3 addr2) oct4b = (octet4 addr2) + + + +-- HUnit Tests +mk_testaddr :: Int -> Int -> Int -> Int -> IPv4Address +mk_testaddr a b c d = + IPv4Address oct1 oct2 oct3 oct4 + where + oct1 = octet_from_int a + oct2 = octet_from_int b + oct3 = octet_from_int c + oct4 = octet_from_int d + + +test_most_sig_bit_different1 = + TestCase $ assertEqual "10.1.1.0 and 10.1.0.0 differ in bit 24" (most_sig_bit_different (mk_testaddr 10 1 1 0) (mk_testaddr 10 1 0 0)) TwentyFour + + +test_most_sig_bit_different2 = + TestCase $ assertEqual "10.1.2.0 and 10.1.1.0 differ in bit 23" (most_sig_bit_different (mk_testaddr 10 1 2 0) (mk_testaddr 10 1 1 0)) TwentyThree + + + +ipv4address_tests = [ test_most_sig_bit_different1, + test_most_sig_bit_different2 ] -- 2.44.2