Commit 2e1c6e53 authored by Steffen Michels's avatar Steffen Michels

Merge branch 'add-maxStringLength' into 'master'

Add option to control maximum length of generated strings

See merge request !28
parents 46e52f12 d35c398b
Pipeline #28314 passed with stage
in 45 seconds
...@@ -106,6 +106,7 @@ where ...@@ -106,6 +106,7 @@ where
, "RandomSeed N: a custom random seed" , "RandomSeed N: a custom random seed"
, "Skew N: 0 for symmetric test generation; positive for right-skewn generation; negative for left-skewn generation" , "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" , "MaxDepth N: the maximum tree depth in generated test cases"
, "MaxStringLength N: the maximum length of generated strings"
, "Output options:" , "Output options:"
, "- Quiet: only show the end result" , "- Quiet: only show the end result"
, "- Concise N: show a test counter for every N tests" , "- Concise N: show a test counter for every N tests"
......
...@@ -25,6 +25,7 @@ generic ggen a :: !GenState -> [a] ...@@ -25,6 +25,7 @@ generic ggen a :: !GenState -> [a]
:: GenState = :: GenState =
{ depth :: !Int //* depth { depth :: !Int //* depth
, maxDepth :: !Int , maxDepth :: !Int
, maxStringLength :: !Int
, path :: ![ConsPos] //* path to nonrecursive constructor , path :: ![ConsPos] //* path to nonrecursive constructor
, mode :: !Mode , mode :: !Mode
, recInfo :: !Map TypeName (Set TypeName) , recInfo :: !Map TypeName (Set TypeName)
...@@ -62,6 +63,6 @@ derive ggen (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,) ...@@ -62,6 +63,6 @@ derive ggen (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
derive ggen [], [!], [ !], [!!] derive ggen [], [!], [ !], [!!]
derive ggen {}, {!} derive ggen {}, {!}
maxint :: Int maxint :: Int
minint :: Int minint :: Int
StrLen :== 16384 defaultMaxStrLen :== 16384
...@@ -54,6 +54,7 @@ genState :: GenState ...@@ -54,6 +54,7 @@ genState :: GenState
genState = genState =
{ depth = 0 { depth = 0
, maxDepth = maxint , maxDepth = maxint
, maxStringLength = defaultMaxStrLen
, path = [] , path = []
, mode = SkewGeneration { skewl = 1 , mode = SkewGeneration { skewl = 1
, skewr = 3 , skewr = 3
...@@ -210,7 +211,9 @@ where ...@@ -210,7 +211,9 @@ where
randIntToReal :: Int -> Real randIntToReal :: Int -> Real
randIntToReal x = (toReal x + if (x >= 0) 0.0 4294967296.0) / 4294967295.0 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 (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
derive ggen [], [!], [ !], [!!] derive ggen [], [!], [ !], [!!]
......
...@@ -76,15 +76,16 @@ generateAll :: !GenState -> [a] | ggen{|*|} a //& genType{|*|} a ...@@ -76,15 +76,16 @@ generateAll :: !GenState -> [a] | ggen{|*|} a //& genType{|*|} a
//--- testing --// //--- testing --//
:: Testoption :: Testoption
= Tests Int = Tests !Int
| Fails Int | Fails !Int
| Args Int | Args !Int
| RandomSeed Int | RandomSeed !Int
| RandomList [Int] | RandomList ![Int]
| Skew Int | Skew !Int
| Bent | Bent
| MaxDepth Int | MaxDepth !Int
| ArgTypes [GenType] | MaxStringLength !Int
| ArgTypes ![GenType]
/** /**
* The combined results of all tests for a single property. * The combined results of all tests for a single property.
......
...@@ -290,12 +290,13 @@ Test options p = testConfig config.randoms {config & randoms = []} p ...@@ -290,12 +290,13 @@ Test options p = testConfig config.randoms {config & randoms = []} p
where where
config = foldl handleOption defaultTestConfig options config = foldl handleOption defaultTestConfig options
handleOption c (Tests i) = {c & maxTests = i, maxArgs = 2*i} handleOption c (Tests i) = {c & maxTests = i, maxArgs = 2*i}
handleOption c (Fails i) = {c & fails = i} handleOption c (Fails i) = {c & fails = i}
handleOption c (Args i) = {c & maxArgs = i} handleOption c (Args i) = {c & maxArgs = i}
handleOption c (RandomSeed i) = {c & randoms = genRandInt i} handleOption c (RandomSeed i) = {c & randoms = genRandInt i}
handleOption c (RandomList r) = {c & randoms = r} handleOption c (RandomList r) = {c & randoms = r}
handleOption c (MaxDepth i) = {c & genState = {c.genState & maxDepth = i}} handleOption c (MaxDepth i) = {c & genState = {c.genState & maxDepth = i}}
handleOption c (MaxStringLength i) = {c & genState = {c.genState & maxStringLength = i}}
handleOption c (Skew s) 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 = 1, skewr = s}}}
| s < 0 = {c & genState = {c.genState & mode = SkewGeneration {skewl = ~s, skewr = 1}}} | 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