]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/IPv4Address.hs
Add some more tests; minor code cleanup.
[hath.git] / src / IPv4Address.hs
index 7c4436781099b5be4ae98434b0455772145e9ab8..15e69665e7ab8e22c4bd027b401860d579cf3727 100644 (file)
@@ -180,10 +180,10 @@ ipv4address_to_int :: IPv4Address -> Int
 ipv4address_to_int addr =
   (shifted_oct1) + (shifted_oct2) + (shifted_oct3) + oct4
   where
-    oct1 = octet_to_int (octet1 addr)
-    oct2 = octet_to_int (octet2 addr)
-    oct3 = octet_to_int (octet3 addr)
-    oct4 = octet_to_int (octet4 addr)
+    oct1 = fromEnum (octet1 addr)
+    oct2 = fromEnum (octet2 addr)
+    oct3 = fromEnum (octet3 addr)
+    oct4 = fromEnum (octet4 addr)
 
     shifted_oct1 = oct1 * 2^(24 :: Integer)
     shifted_oct2 = oct2 * 2^(16 :: Integer)
@@ -346,7 +346,8 @@ ipv4address_tests =
     test_maxBound,
     test_minBound,
     test_most_sig_bit_different1,
-    test_most_sig_bit_different2 ]
+    test_most_sig_bit_different2,
+    test_to_enum ]
 
 ipv4address_properties :: Test
 ipv4address_properties =
@@ -423,3 +424,10 @@ test_most_sig_bit_different2 =
     bit = most_sig_bit_different addr1 addr2
 
 
+test_to_enum :: Test
+test_to_enum =
+  testCase desc $ assertEqual desc expected actual
+  where
+    desc     = "192.168.0.0 in base-10 is 3232235520"
+    expected = mk_testaddr 192 168 0 0
+    actual   = toEnum 3232235520