Commit d35c398b authored by Camil Staps's avatar Camil Staps 🚀

Add option to control maximum length of generated strings

parent 46e52f12
Pipeline #28313 passed with stage
in 44 seconds
......@@ -106,6 +106,7 @@ where
, "RandomSeed N: a custom random seed"
, "Skew N: 0 for symmetric test generation; positive for right-skewn generation; negative for left-skewn generation"
, "MaxDepth N: the maximum tree depth in generated test cases"
, "MaxStringLength N: the maximum length of generated strings"
, "Output options:"
, "- Quiet: only show the end result"
, "- Concise N: show a test counter for every N tests"
......
......@@ -25,6 +25,7 @@ generic ggen a :: !GenState -> [a]
:: GenState =
{ depth :: !Int //* depth
, maxDepth :: !Int
, maxStringLength :: !Int
, path :: ![ConsPos] //* path to nonrecursive constructor
, mode :: !Mode
, recInfo :: !Map TypeName (Set TypeName)
......@@ -62,6 +63,6 @@ derive ggen (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
derive ggen [], [!], [ !], [!!]
derive ggen {}, {!}
maxint :: Int
minint :: Int
StrLen :== 16384
maxint :: Int
minint :: Int
defaultMaxStrLen :== 16384
......@@ -54,6 +54,7 @@ genState :: GenState
genState =
{ depth = 0
, maxDepth = maxint
, maxStringLength = defaultMaxStrLen
, path = []
, mode = SkewGeneration { skewl = 1
, skewr = 3
......@@ -210,7 +211,9 @@ where
randIntToReal :: Int -> Real
randIntToReal x = (toReal x + if (x >= 0) 0.0 4294967296.0) / 4294967295.0
ggen{|String|} s = ["hello world!","Gast","":ggenString StrLen 4.0 32 126 aStream]
ggen{|String|} s = init ++ ["":ggenString s.maxStringLength 4.0 32 126 aStream]
where
init = filter ((>=) s.maxStringLength o size) ["hello world!", "Gast"]
derive ggen (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
derive ggen [], [!], [ !], [!!]
......
......@@ -76,15 +76,16 @@ generateAll :: !GenState -> [a] | ggen{|*|} a //& genType{|*|} a
//--- testing --//
:: Testoption
= Tests Int
| Fails Int
| Args Int
| RandomSeed Int
| RandomList [Int]
| Skew Int
= Tests !Int
| Fails !Int
| Args !Int
| RandomSeed !Int
| RandomList ![Int]
| Skew !Int
| Bent
| MaxDepth Int
| ArgTypes [GenType]
| MaxDepth !Int
| MaxStringLength !Int
| ArgTypes ![GenType]
/**
* The combined results of all tests for a single property.
......
......@@ -290,12 +290,13 @@ Test options p = testConfig config.randoms {config & randoms = []} p
where
config = foldl handleOption defaultTestConfig options
handleOption c (Tests i) = {c & maxTests = i, maxArgs = 2*i}
handleOption c (Fails i) = {c & fails = i}
handleOption c (Args i) = {c & maxArgs = i}
handleOption c (RandomSeed i) = {c & randoms = genRandInt i}
handleOption c (RandomList r) = {c & randoms = r}
handleOption c (MaxDepth i) = {c & genState = {c.genState & maxDepth = i}}
handleOption c (Tests i) = {c & maxTests = i, maxArgs = 2*i}
handleOption c (Fails i) = {c & fails = i}
handleOption c (Args i) = {c & maxArgs = i}
handleOption c (RandomSeed i) = {c & randoms = genRandInt i}
handleOption c (RandomList r) = {c & randoms = r}
handleOption c (MaxDepth i) = {c & genState = {c.genState & maxDepth = i}}
handleOption c (MaxStringLength i) = {c & genState = {c.genState & maxStringLength = i}}
handleOption c (Skew s)
| s > 0 = {c & genState = {c.genState & mode = SkewGeneration {skewl = 1, skewr = s}}}
| s < 0 = {c & genState = {c.genState & mode = SkewGeneration {skewl = ~s, skewr = 1}}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment