]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/Octet.hs
Added Arbitrary instance definitions for the main data types.
[hath.git] / src / Octet.hs
index 04caae54fa6bcefab22d28415f5e2e8f6aa81064..b3e6a0f5d3c1310f38443ca99dc49c43de516e5a 100644 (file)
@@ -1,6 +1,7 @@
 module Octet where
 
 import Test.HUnit
+import Test.QuickCheck
 
 import Bit
 
@@ -23,6 +24,21 @@ instance Show Octet where
     show oct = show (octet_to_int oct)
 
 
+instance Arbitrary Octet where
+    arbitrary = do
+      a1 <- arbitrary :: Gen Bit
+      a2 <- arbitrary :: Gen Bit
+      a3 <- arbitrary :: Gen Bit
+      a4 <- arbitrary :: Gen Bit
+      a5 <- arbitrary :: Gen Bit
+      a6 <- arbitrary :: Gen Bit
+      a7 <- arbitrary :: Gen Bit
+      a8 <- arbitrary :: Gen Bit
+      return (Octet a1 a2 a3 a4 a5 a6 a7 a8)
+
+    coarbitrary _ = variant 0
+
+
 -- Convert each bit to its integer value, and multiply by the
 -- appropriate power of two. Sum them up, and we should get an integer
 -- between 0 and 255.