+--
+-- We have two different tests to show that toEnum and fromEnum are
+-- inverses of one another. This part of the code isn't really
+-- type-safe, because the stupid Enum class insists that we use a
+-- machine 'Int' for our representation. Since IPv4 addresses can
+-- correspond to very large 32-bit integers, there's a possibility
+-- that our math is wrong in 32- but not 64-bits, and vice-versa.
+--
+-- tl;dr we want to ensure that this test passes when the 'Int' type
+-- is both 32-bit and 64-bit.
+
+-- Generate "Small" 64-bit numbers, because almost all 64-bit integers are
+-- too large to satisfy our predicate (i.e. also be 32-bit integers).
+prop_from_enum_to_enum_inverses_x64 :: TestTree
+prop_from_enum_to_enum_inverses_x64 =
+ testProperty "fromEnum and toEnum are inverses (x64)" prop
+ where
+ prop :: (Small Int64) -> Property
+ prop x =
+ 0 <= x && x <= 2^(32 :: Integer) - 1 ==>
+ fromIntegral (fromEnum (toEnum (fromIntegral x) :: IPv4Address)) == x
+
+-- According to the QuickCheck documentation, we need the "Large"
+-- modifier to ensure that the test cases are drawn from the entire
+-- range of Int32 values.
+prop_from_enum_to_enum_inverses_x32 :: TestTree
+prop_from_enum_to_enum_inverses_x32 =
+ testProperty "fromEnum and toEnum are inverses (x32)" prop