commit 16740a7f0a7c5a7db2d61c496e805539e1b83fb3
parent 9bec4d761ef6e49b7331070947c2639076bd52f0
Author: Jared Tobin <jared@jtobin.io>
Date: Wed, 22 Jan 2025 12:16:54 +0400
test: skeleton
Diffstat:
2 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/ppad-fw.cabal b/ppad-fw.cabal
@@ -27,3 +27,19 @@ library
build-depends:
base >= 4.9 && < 5
+test-suite fw-tests
+ type: exitcode-stdio-1.0
+ default-language: Haskell2010
+ hs-source-dirs: test
+ main-is: Main.hs
+
+ ghc-options:
+ -rtsopts -Wall -O2
+
+ build-depends:
+ base
+ , bytestring
+ , ppad-fw
+ , tasty
+ , tasty-quickcheck
+
diff --git a/test/Main.hs b/test/Main.hs
@@ -0,0 +1,35 @@
+module Main where
+
+import Data.Word.Extended
+import Test.Tasty
+import qualified Test.Tasty.QuickCheck as Q
+
+instance Q.Arbitrary Word256 where
+ arbitrary = do
+ w0 <- Q.arbitrary
+ w1 <- Q.arbitrary
+ w2 <- Q.arbitrary
+ w3 <- Q.arbitrary
+ pure (Word256 w0 w1 w2 w3)
+
+to_word256_inverts_to_integer :: Word256 -> Bool
+to_word256_inverts_to_integer w256 =
+ to_word256 (to_integer w256) == w256
+
+to_integer_inverts_to_word256 :: Integer -> Bool
+to_integer_inverts_to_word256 n =
+ to_integer (to_word256 n) == n
+
+conversion = testGroup "conversion" [
+ Q.testProperty "to_word256 . to_integer ~ id" $
+ Q.withMaxSuccess 1000 to_word256_inverts_to_integer
+ , Q.testProperty "to_integer . to_word256 ~ id" $
+ Q.withMaxSuccess 1000 to_integer_inverts_to_word256
+ ]
+
+main :: IO ()
+main = defaultMain $ testGroup "ppad-fw" [
+ conversion
+ ]
+
+