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(..))
-- 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