2024-09-29 19:26:40 +02:00
|
|
|
|
|
|
|
|
-- | Generate test cases for Nim
|
|
|
|
|
|
|
|
|
|
module TestGen.TestPermutation where
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
import Data.Array
|
|
|
|
|
import Data.List
|
|
|
|
|
|
|
|
|
|
import System.IO
|
|
|
|
|
|
2024-10-02 22:55:15 +02:00
|
|
|
import Permutations
|
2024-10-01 16:00:27 +02:00
|
|
|
import Goldilocks
|
|
|
|
|
import Common
|
2024-09-29 19:26:40 +02:00
|
|
|
|
2024-10-01 16:00:27 +02:00
|
|
|
import TestGen.Shared
|
2024-09-29 19:26:40 +02:00
|
|
|
|
2024-10-01 16:00:27 +02:00
|
|
|
--------------------------------------------------------------------------------
|
2024-09-29 19:26:40 +02:00
|
|
|
|
|
|
|
|
perms :: String -> (State -> State) -> [State] -> String
|
|
|
|
|
perms varname f xs = unlines (header : stuff ++ footer) where
|
|
|
|
|
header = "const " ++ varname ++ "* : array[" ++ show (length xs) ++ ", tuple[xs:F12, ys:F12]] = "
|
|
|
|
|
footer = [" ]",""]
|
|
|
|
|
stuff = showListWith nimShowStatePair [ (x, f x) | x<-xs ]
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
2024-10-16 17:30:29 +02:00
|
|
|
testStates12 :: [State]
|
|
|
|
|
testStates12 =
|
|
|
|
|
[ listToState' 12 [ fromInteger (a + b*i) | i<-[0..11] ]
|
2024-09-29 19:26:40 +02:00
|
|
|
| a <- [0,10,200,3000]
|
|
|
|
|
, b <- [1, 7, 23, 666]
|
|
|
|
|
]
|
|
|
|
|
|
2024-10-16 17:30:29 +02:00
|
|
|
testStates16 :: [State]
|
|
|
|
|
testStates16 =
|
|
|
|
|
[ listToState' 16 [ fromInteger (a + b*i) | i<-[0..15] ]
|
|
|
|
|
| a <- [0,10,200,3000]
|
|
|
|
|
, b <- [1, 7, 23, 666]
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
testStates :: Hash -> [State]
|
|
|
|
|
testStates hash = case hashT hash of
|
|
|
|
|
12 -> testStates12
|
|
|
|
|
16 -> testStates16
|
|
|
|
|
|
2024-09-29 19:26:40 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
2024-10-02 22:55:15 +02:00
|
|
|
printTests :: Hash -> IO ()
|
|
|
|
|
printTests hash = hPrintTests stdout hash
|
2024-09-29 19:26:40 +02:00
|
|
|
|
2024-10-02 22:55:15 +02:00
|
|
|
hPrintTests :: Handle -> Hash -> IO ()
|
|
|
|
|
hPrintTests h hash = hPutStrLn h $ unlines
|
2024-10-16 17:30:29 +02:00
|
|
|
[ perms "testcases_perm" (permute hash) (testStates hash)
|
2024-09-29 19:26:40 +02:00
|
|
|
]
|
|
|
|
|
|
2024-10-02 22:55:15 +02:00
|
|
|
writeTests :: Hash -> IO ()
|
|
|
|
|
writeTests hash = withFile "permTestCases.nim" WriteMode $ \h -> do
|
2024-09-29 19:26:40 +02:00
|
|
|
hPutStrLn h "# generated by TestGen/TestPermutation.hs\n"
|
2024-10-01 21:00:27 +02:00
|
|
|
hPutStrLn h "import goldilocks_hash/types\n"
|
2024-10-02 22:55:15 +02:00
|
|
|
hPrintTests h hash
|
2024-09-29 19:26:40 +02:00
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|