mirror of
https://github.com/logos-storage/nim-goldilocks-hash.git
synced 2026-01-04 22:53:11 +00:00
44 lines
1.1 KiB
Haskell
44 lines
1.1 KiB
Haskell
|
|
-- | Generate test cases for Nim
|
|
|
|
module TestGen.TestMerkle where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Data.Array
|
|
import Data.List
|
|
import Data.Word
|
|
|
|
import System.IO
|
|
|
|
import Merkle
|
|
import Goldilocks
|
|
import Common
|
|
|
|
import TestGen.Shared
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
intToDigest :: Integer -> Digest
|
|
intToDigest k = MkDigest (fromInteger k) 0 0 0
|
|
|
|
merkleDigest :: Hash -> Integer -> Digest
|
|
merkleDigest hash max = merkleRoot hash $ map intToDigest [1..max]
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
printTests :: Hash -> IO ()
|
|
printTests hash = hPrintTests stdout hash
|
|
|
|
hPrintTests :: Handle -> Hash -> IO ()
|
|
hPrintTests h hash= hPutStrLn h $ unlines $
|
|
[ digests "testcases_merkleroot" (merkleDigest hash) [1..175] ]
|
|
|
|
writeTests :: Hash -> IO ()
|
|
writeTests hash = withFile "merkleTestCases.nim" WriteMode $ \h -> do
|
|
hPutStrLn h "# generated by TestGen/TestMerkle.hs\n"
|
|
hPutStrLn h "import goldilocks_hash/types\n"
|
|
hPrintTests h hash
|
|
|
|
--------------------------------------------------------------------------------
|