X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FIPv4Address.hs;h=7e502125722cbfb354a53d517acd206a3fe678ad;hb=0aa85b3d0ae468def9ee478579cd6558aea5cde3;hp=fca1d0fe006cc33c659f4e883bfda3897f83f4d2;hpb=13b975060857b8acd64b7231074dc4a0c0a2915a;p=hath.git diff --git a/src/IPv4Address.hs b/src/IPv4Address.hs index fca1d0f..7e50212 100644 --- a/src/IPv4Address.hs +++ b/src/IPv4Address.hs @@ -9,22 +9,28 @@ where import Test.Tasty ( TestTree, testGroup ) import Test.Tasty.HUnit ( (@?=), testCase ) import Test.Tasty.QuickCheck ( - Arbitrary(..), + Arbitrary( arbitrary ), Gen, Property, (==>), testProperty ) -import Maskable (Maskable(..)) -import Maskbits (Maskbits(..)) -import Octet (Octet(..)) +import Maskable ( Maskable( apply_mask) ) +import Maskbits ( + Maskbits( + Zero, One, Two, Three, Four, Five, Six, Seven, Eight, + Nine, Ten, Eleven, Twelve, Thirteen, Fourteen, Fifteen, Sixteen, + Seventeen, Eighteen, Nineteen, Twenty, TwentyOne, TwentyTwo, TwentyThree, + TwentyFour, TwentyFive, TwentySix, TwentySeven, TwentyEight, TwentyNine, + Thirty, ThirtyOne, ThirtyTwo ) ) +import Octet ( Octet( b1, b2, b3, b4, b5, b6, b7, b8) ) data IPv4Address = IPv4Address { octet1 :: Octet, octet2 :: Octet, octet3 :: Octet, octet4 :: Octet } - deriving (Eq) + deriving (Eq, Ord) instance Show IPv4Address where @@ -335,6 +341,10 @@ ipv4address_tests = test_minBound, test_most_sig_bit_different1, test_most_sig_bit_different2, + test_ord_instance1, + test_ord_instance2, + test_ord_instance3, + test_ord_instance4, test_to_enum ] ipv4address_properties :: TestTree @@ -423,3 +433,45 @@ test_to_enum = desc = "192.168.0.0 in base-10 is 3232235520" expected = mk_testaddr 192 168 0 0 actual = toEnum 3232235520 :: IPv4Address + + +test_ord_instance1 :: TestTree +test_ord_instance1 = + testCase desc $ actual @?= expected + where + desc = "127.0.0.0 is less than 127.0.0.1" + addr1 = mk_testaddr 127 0 0 0 + addr2 = mk_testaddr 127 0 0 1 + expected = True + actual = addr1 <= addr2 + + +test_ord_instance2 :: TestTree +test_ord_instance2 = + testCase desc $ actual @?= expected + where + desc = "127.0.0.0 is less than 127.0.1.0" + addr1 = mk_testaddr 127 0 0 0 + addr2 = mk_testaddr 127 0 1 0 + expected = True + actual = addr1 <= addr2 + +test_ord_instance3 :: TestTree +test_ord_instance3 = + testCase desc $ actual @?= expected + where + desc = "127.0.0.0 is less than 127.1.0.0" + addr1 = mk_testaddr 127 0 0 0 + addr2 = mk_testaddr 127 1 0 0 + expected = True + actual = addr1 <= addr2 + +test_ord_instance4 :: TestTree +test_ord_instance4 = + testCase desc $ actual @?= expected + where + desc = "127.0.0.0 is less than 128.0.0.0" + addr1 = mk_testaddr 127 0 0 0 + addr2 = mk_testaddr 128 0 0 0 + expected = True + actual = addr1 <= addr2