X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FIPv4Address.hs;h=7e502125722cbfb354a53d517acd206a3fe678ad;hb=0aa85b3d0ae468def9ee478579cd6558aea5cde3;hp=698594437d7f4a4b0470e96fc67d743221b2a5aa;hpb=6b71fc1e444cc95acdef91ad814e4f97b01ec52e;p=hath.git diff --git a/src/IPv4Address.hs b/src/IPv4Address.hs index 6985944..7e50212 100644 --- a/src/IPv4Address.hs +++ b/src/IPv4Address.hs @@ -30,7 +30,7 @@ data IPv4Address = octet2 :: Octet, octet3 :: Octet, octet4 :: Octet } - deriving (Eq) + deriving (Eq, Ord) instance Show IPv4Address where @@ -341,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 @@ -429,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