2024-10-03 00:26:28 +02:00

57 lines
1.7 KiB
Haskell

-- | Generate test cases for Nim
module TestGen.TestCompress where
--------------------------------------------------------------------------------
import Data.Array
import Data.List
import System.IO
import Merkle
import Goldilocks
import Common
import TestGen.Shared
--------------------------------------------------------------------------------
printArray :: String -> [F] -> String
printArray varname xs = unlines (header : stuff ++ footer) where
header = "const " ++ varname ++ "* : array[" ++ show (length xs) ++ ", F] = "
footer = [" ]",""]
stuff = showListWith nimShowF xs
--------------------------------------------------------------------------------
left = map toF [1..4]
right = map toF [5..8]
compress_ :: Hash -> Int -> [F] -> [F] -> [F]
compress_ hash key as bs = digestToList $ keyedCompress hash key (listToDigest as) (listToDigest bs)
--------------------------------------------------------------------------------
printTests :: Hash -> IO ()
printTests hash = hPrintTests stdout hash
hPrintTests :: Handle -> Hash -> IO ()
hPrintTests h hash = hPutStrLn h $ unlines
[ printArray "refInp1" left
, printArray "refInp2" right
, printArray "refOutKey0" (compress_ hash 0 left right)
, printArray "refOutKey1" (compress_ hash 1 left right)
, printArray "refOutKey2" (compress_ hash 2 left right)
, printArray "refOutKey3" (compress_ hash 3 left right)
]
writeTests :: Hash -> IO ()
writeTests hash = withFile "compressTestCases.nim" WriteMode $ \h -> do
hPutStrLn h "# generated by TestGen/TestCompress.hs\n"
hPutStrLn h "import goldilocks_hash/types\n"
hPrintTests h hash
--------------------------------------------------------------------------------