]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/Cidr.hs
Fixed one of the new tests (min/max).
[hath.git] / src / Cidr.hs
index 8fc014f6cf5b062f8ae019d3b990c22a9604e9b8..823f43fc8b6160cd915aa7d0afd17938399250d3 100644 (file)
@@ -60,8 +60,11 @@ equivalent (Cidr addr1 mbits1) (Cidr addr2 mbits2) =
 -- Returns the mask portion of a CIDR address. That is, everything
 -- after the trailing slash.
 maskbits_from_cidr_string :: String -> Maskbits
-maskbits_from_cidr_string s =
-    maskbits_from_string ((splitWith (`elem` "/") s) !! 1)
+maskbits_from_cidr_string s
+    | length partlist == 2 = maskbits_from_string (partlist !! 1)
+    | otherwise = Maskbits.None
+      where
+        partlist = (splitWith (`elem` "/") s)
 
 
 -- Takes an IP address String in CIDR notation, and returns a list of
@@ -242,6 +245,22 @@ adjacent cidr1 cidr2
 
 -- HUnit Tests
 
+test_min_host1 :: Test
+test_min_host1 =
+    TestCase $ assertEqual "The minimum host in 10.0.0.0/24 is 10.0.0.0" expected actual
+    where
+      actual = show $ min_host (cidr_from_string "10.0.0.0/24")
+      expected = "10.0.0.0"
+
+
+test_max_host1 :: Test
+test_max_host1 =
+    TestCase $ assertEqual "The maximum host in 10.0.0.0/24 is 10.0.0.255" expected actual
+    where
+      actual = show $ max_host (cidr_from_string "10.0.0.0/24")
+      expected = "10.0.0.255"
+
+
 test_equality1 :: Test
 test_equality1 =
     TestCase $ assertEqual "10.1.1.0/23 equals itself" True (cidr1 == cidr1)
@@ -353,7 +372,9 @@ test_combine_all2 =
 
 
 cidr_tests :: [Test]
-cidr_tests = [ test_equality1,
+cidr_tests = [ test_min_host1,
+               test_max_host1,
+               test_equality1,
                test_contains1,
                test_contains2,
                test_contains_proper1,