]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/Octet.hs
Switch from test-framework to tasty.
[hath.git] / src / Octet.hs
index 6d6c8c85f79265ab95eb6013082a8ef61c4af5ee..55f075e8a5810247dc9d7df2342b741ea6f82d30 100644 (file)
@@ -1,15 +1,17 @@
 module Octet (
   Octet(..),
   octet_properties,
-  octet_tests,
-  )
+  octet_tests )
 where
 
-import Test.HUnit (assertEqual)
-import Test.Framework (Test, testGroup)
-import Test.Framework.Providers.HUnit (testCase)
-import Test.Framework.Providers.QuickCheck2 (testProperty)
-import Test.QuickCheck (Arbitrary(..), Gen, Property, (==>))
+import Test.QuickCheck ( Gen ) -- Not re-exported by tasty
+import Test.Tasty ( TestTree, testGroup )
+import Test.Tasty.HUnit ( (@?=), testCase )
+import Test.Tasty.QuickCheck (
+  Arbitrary(..),
+  Property,
+  (==>),
+  testProperty )
 
 import Bit as B (Bit(..))
 import Maskable (Maskable(..))
@@ -148,64 +150,67 @@ instance Read Octet where
 
 
 -- Test lists.
-octet_tests :: Test
+octet_tests :: TestTree
 octet_tests =
   testGroup "Octet Tests" [
     test_octet_from_int1,
     test_octet_mask1,
     test_octet_mask2 ]
 
-octet_properties :: Test
+octet_properties :: TestTree
 octet_properties =
   testGroup
     "Octet Properties "
-    [ testProperty
-        "fromEnum/toEnum are inverses"
-        prop_from_enum_to_enum_inverses,
-      testProperty
-        "read/show are inverses"
-        prop_read_show_inverses ]
+    [ prop_from_enum_to_enum_inverses,
+      prop_read_show_inverses ]
 
 -- QuickCheck properties
-prop_from_enum_to_enum_inverses :: Int -> Property
-prop_from_enum_to_enum_inverses x =
-  (0 <= x) && (x <= 255) ==>
-    fromEnum (toEnum x :: Octet) == x
-
-prop_read_show_inverses :: Int -> Property
-prop_read_show_inverses x =
-  (0 <= x) && (x <= 255) ==> x' == x
+prop_from_enum_to_enum_inverses :: TestTree
+prop_from_enum_to_enum_inverses =
+  testProperty "fromEnum and toEnum are inverses" prop
   where
-    oct :: Octet
-    oct = read $ show x
+    prop :: Int -> Property
+    prop x =
+      (0 <= x) && (x <= 255) ==>
+        fromEnum (toEnum x :: Octet) == x
+
+prop_read_show_inverses :: TestTree
+prop_read_show_inverses =
+  testProperty "read and show are inverses" prop
+  where
+    prop :: Int -> Property
+    prop x = (0 <= x) && (x <= 255) ==> x' == x
+      where
+        oct :: Octet
+        oct = read $ show x
+
+        x' :: Int
+        x' = read $ show oct
 
-    x' :: Int
-    x' = read $ show oct
 
 -- HUnit Tests
-test_octet_from_int1 :: Test
+test_octet_from_int1 :: TestTree
 test_octet_from_int1 =
-  testCase desc $ assertEqual desc oct1 oct2
+  testCase desc $ actual @?= expected
   where
     desc = "octet_from_int 128 should parse as 10000000"
-    oct1 = Octet B.One B.Zero B.Zero B.Zero B.Zero B.Zero B.Zero B.Zero
-    oct2 = toEnum 128
+    expected = Octet B.One B.Zero B.Zero B.Zero B.Zero B.Zero B.Zero B.Zero
+    actual = toEnum 128
+
 
-test_octet_mask1 :: Test
+test_octet_mask1 :: TestTree
 test_octet_mask1 =
-  testCase desc $
-    assertEqual desc oct2 (apply_mask oct1 Four B.Zero)
+  testCase desc $ actual @?= expected
   where
     desc = "The network bits of 255/4 should equal 240"
-    oct1 = toEnum 255
-    oct2 = toEnum 240 :: Octet
+    expected = toEnum 240 :: Octet
+    actual = apply_mask (toEnum 255) Four B.Zero
 
 
-test_octet_mask2 :: Test
+test_octet_mask2 :: TestTree
 test_octet_mask2 =
-  testCase desc $
-    assertEqual desc oct2 (apply_mask oct1 Maskbits.One B.Zero)
+  testCase desc $ actual @?= expected
   where
     desc = "The network bits of 255/1 should equal 128"
-    oct1 = toEnum 255
-    oct2 = toEnum 128 :: Octet
+    expected = toEnum 128 :: Octet
+    actual = apply_mask (toEnum 255) Maskbits.One B.Zero