diff --git a/Tests/generatorSystem.wlt b/Tests/generatorSystem.wlt index 458f30a9..1850f50a 100644 --- a/Tests/generatorSystem.wlt +++ b/Tests/generatorSystem.wlt @@ -8,34 +8,34 @@ Global`declareSystemParameter = SetReplace`PackageScope`declareSystemParameter; Global`initializeSystemGenerators = SetReplace`PackageScope`initializeSystemGenerators; - declareSystemParameter[maxSomething, Infinity, _?(GreaterEqualThan[0]), "is a max param."]; - declareSystemParameter[minSomething, 0, _?(GreaterEqualThan[0]), "is a min param."]; - declareSystemParameter[pickNumber, None, None | 0 | 1 | 2, "is a pick param."]; + declareSystemParameter[maxEventSize, Infinity, _ ? (GreaterEqualThan[0]), "is a max parameter for a test value."]; + declareSystemParameter[minEventSize, 0, _ ? (GreaterEqualThan[0]), "is a min parameter for a test value."]; + declareSystemParameter[eventType, None, None | 0 | 1 | 2, "is an optional choice between 0, 1, and 2."]; - declareSystem[echoSystem, List, _Integer, {maxSomething, pickNumber}, True]; - declareSystem[needSomethingForPicking, + declareSystem[genericSystem, List, _Integer, {maxEventSize, eventType}, True]; + declareSystem[systemWithParameterDependencies, List, _Integer, - {minSomething, maxSomething, pickNumber}, - Implies[pickNumber, minSomething || maxSomething]]; - declareSystem[minXorMax, List, _Integer, {minSomething, maxSomething}, Xor[minSomething, maxSomething]]; - declareSystem[listInit, List, _List, {minSomething, maxSomething, pickNumber}, True]; - declareSystem[realSystem, List, _, {MaxDestroyerEvents, MaxEvents, MaxGeneration}, True]; + {minEventSize, maxEventSize, eventType}, + Implies[eventType, minEventSize || maxEventSize]]; + declareSystem[minXorMaxSystem, List, _Integer, {minEventSize, maxEventSize}, Xor[minEventSize, maxEventSize]]; + declareSystem[listStateSystem, List, _List, {minEventSize, maxEventSize, eventType}, True]; + declareSystem[realParameterSystem, List, _, {MaxDestroyerEvents, MaxEvents, MaxGeneration}, True]; - declareSystemGenerator[identityGenerator, internalIdentityGenerator, <||>, Identity, "does nothing."]; - declareSystemGenerator[pick2Generator, internalPick2Generator, <|pickNumber -> 2|>, picked, "picks 2."]; + declareSystemGenerator[genericGenerator, internalGenericGenerator, <||>, Identity, "does nothing."]; + declareSystemGenerator[typeTwoGenerator, internalTypeTwoGenerator, <|eventType -> 2|>, property, "picks 2."]; Unprotect[$SetReplaceSystems, $SetReplaceGenerators, GenerateSingleHistory, GenerateMultihistory]; initializeSystemGenerators[]; Protect[$SetReplaceSystems, $SetReplaceGenerators, GenerateSingleHistory, GenerateMultihistory]; ), "tests" -> { - (* Internal errors *) - VerificationTest[declareSystem[invalidSystem, List, _, {minSomething}, minSomething && !minSomething], + (* Declaration errors *) + VerificationTest[declareSystem[invalidSystem, List, _, {minEventSize}, minEventSize && !minEventSize], _, {SetReplace::unsatisfiableParameterDependencies}, SameTest -> MatchQ], - VerificationTest[declareSystem[invalidSystem, List, _, {minSomething}], + VerificationTest[declareSystem[invalidSystem, List, _, {minEventSize}], _, {SetReplace::invalidSystemDeclaration}, SameTest -> MatchQ], @@ -49,109 +49,120 @@ SameTest -> MatchQ], (* Zero args *) - testUnevaluated[identityGenerator[], {identityGenerator::argm}], + testUnevaluated[genericGenerator[], {genericGenerator::argm}], (* One arg *) - testUnevaluated[identityGenerator[0], {}], - testUnevaluated[identityGenerator[echoSystem[0]], {}], + testUnevaluated[genericGenerator[0], {}], + testUnevaluated[genericGenerator[genericSystem[]], {}], (* Two args *) - testUnevaluated[identityGenerator[0, 0], {identityGenerator::unknownSystem}], + testUnevaluated[genericGenerator[0, 0], {genericGenerator::unknownSystem}], + testUnevaluated[genericGenerator[genericSystem[], "test"], {}], (* parameters are not yet parsed at this stage *) VerificationTest[ - identityGenerator[echoSystem[0], 0], {echoSystem[0], 0, <|maxSomething -> Infinity, pickNumber -> None|>}], - testUnevaluated[identityGenerator[echoSystem[0], "test"], {}], (* parameters are not yet parsed at this stage *) - - (* Parameters *) - testUnevaluated[identityGenerator[echoSystem[0], 0, abc], {identityGenerator::invalidGeneratorParameterSpec}], - testUnevaluated[identityGenerator[echoSystem[0], 0, {abc}], {identityGenerator::invalidGeneratorParameterSpec}], - testUnevaluated[identityGenerator[echoSystem[0], 0, abc -> 4], {identityGenerator::unknownParameter}], - testUnevaluated[identityGenerator[echoSystem[0], maxSomething -> 4], {}], (* no init, treated as an operator *) - VerificationTest[identityGenerator[echoSystem[0], 0, maxSomething -> 4], - {echoSystem[0], 0, <|maxSomething -> 4, pickNumber -> None|>}], - testUnevaluated[identityGenerator[echoSystem[0], 0, maxSomething -> -1], {identityGenerator::invalidParameter}], - testUnevaluated[identityGenerator[echoSystem[0], 0, minSomething -> 4], {identityGenerator::unknownParameter}], + genericGenerator[genericSystem[], 0], {genericSystem[], 0, <|maxEventSize -> Infinity, eventType -> None|>}], + + (* Parameters spec *) + testUnevaluated[genericGenerator[genericSystem[], 0, abc], {genericGenerator::invalidGeneratorParameterSpec}], + testUnevaluated[genericGenerator[genericSystem[], 0, {abc}], {genericGenerator::invalidGeneratorParameterSpec}], + testUnevaluated[genericGenerator[genericSystem[], 0, abc -> 4], {genericGenerator::unknownParameter}], + testUnevaluated[genericGenerator[genericSystem[], maxEventSize -> 4], {}], (* no init, treated as operator form *) + VerificationTest[genericGenerator[genericSystem[], 0, maxEventSize -> 4], + {genericSystem[], 0, <|maxEventSize -> 4, eventType -> None|>}], + testUnevaluated[genericGenerator[genericSystem[], 0, maxEventSize -> -1], {genericGenerator::invalidParameter}], + testUnevaluated[genericGenerator[genericSystem[], 0, minEventSize -> 4], {genericGenerator::unknownParameter}], VerificationTest[ - identityGenerator[echoSystem[0], 0, ##], {echoSystem[0], 0, <|maxSomething -> 4, pickNumber -> 0|>}] & @@@ { - {maxSomething -> 4, pickNumber -> 0}, - {{maxSomething -> 4}, pickNumber -> 0}, - {maxSomething -> 4, {pickNumber -> 0}}, - {<|maxSomething -> 4|>, {{pickNumber -> 0}}} + genericGenerator[genericSystem[], 0, ##], {genericSystem[], 0, <|maxEventSize -> 4, eventType -> 0|>}] & @@@ { + {maxEventSize -> 4, eventType -> 0}, + {{maxEventSize -> 4}, eventType -> 0}, + {maxEventSize -> 4, {eventType -> 0}}, + {<|maxEventSize -> 4|>, {{eventType -> 0}}} }, - VerificationTest[identityGenerator[echoSystem[0], 0, pickNumber -> 0, pickNumber -> 1], - {echoSystem[0], 0, <|maxSomething -> Infinity, pickNumber -> 1|>}], - testUnevaluated[identityGenerator[echoSystem[0], 0, pickNumber -> 0, pickNumber -> 1, 3], - {identityGenerator::invalidGeneratorParameterSpec}], + VerificationTest[genericGenerator[genericSystem[], 0, eventType -> 0, eventType -> 1], + {genericSystem[], 0, <|maxEventSize -> Infinity, eventType -> 1|>}], + testUnevaluated[genericGenerator[genericSystem[], 0, eventType -> 0, eventType -> 1, 3], + {genericGenerator::invalidGeneratorParameterSpec}], - VerificationTest[ - pick2Generator[echoSystem[0], 0], picked[{echoSystem[0], 0, <|maxSomething -> Infinity, pickNumber -> 2|>}]], - testUnevaluated[pick2Generator[echoSystem[0], 0, pickNumber -> 1], {pick2Generator::forbiddenParameter}], - VerificationTest[pick2Generator[echoSystem[0], 0, maxSomething -> 2], - picked[{echoSystem[0], 0, <|maxSomething -> 2, pickNumber -> 2|>}]], + (* Generator with predefined parameters *) + VerificationTest[typeTwoGenerator[genericSystem[], 0], + property[{genericSystem[], 0, <|maxEventSize -> Infinity, eventType -> 2|>}]], + testUnevaluated[typeTwoGenerator[genericSystem[], 0, eventType -> 1], {typeTwoGenerator::forbiddenParameter}], + VerificationTest[typeTwoGenerator[genericSystem[], 0, maxEventSize -> 2], + property[{genericSystem[], 0, <|maxEventSize -> 2, eventType -> 2|>}]], + (* Parameter dependencies *) VerificationTest[ - identityGenerator[needSomethingForPicking[0], 0], - {needSomethingForPicking[0], 0, <|minSomething -> 0, maxSomething -> Infinity, pickNumber -> None|>}], + genericGenerator[systemWithParameterDependencies[], 0], + {systemWithParameterDependencies[], 0, <|minEventSize -> 0, maxEventSize -> Infinity, eventType -> None|>}], testUnevaluated[ - identityGenerator[needSomethingForPicking[0], 0, pickNumber -> 2], {identityGenerator::missingParameters}], + genericGenerator[systemWithParameterDependencies[], 0, eventType -> 2], {genericGenerator::missingParameters}], VerificationTest[ - identityGenerator[needSomethingForPicking[0], 0, pickNumber -> 2, minSomething -> 2], - {needSomethingForPicking[0], 0, <|minSomething -> 2, maxSomething -> Infinity, pickNumber -> 2|>}], + genericGenerator[systemWithParameterDependencies[], 0, eventType -> 2, minEventSize -> 2], + {systemWithParameterDependencies[], 0, <|minEventSize -> 2, maxEventSize -> Infinity, eventType -> 2|>}], VerificationTest[ - identityGenerator[needSomethingForPicking[0], 0, pickNumber -> 2, maxSomething -> 2], - {needSomethingForPicking[0], 0, <|minSomething -> 0, maxSomething -> 2, pickNumber -> 2|>}], + genericGenerator[systemWithParameterDependencies[], 0, eventType -> 2, maxEventSize -> 2], + {systemWithParameterDependencies[], 0, <|minEventSize -> 0, maxEventSize -> 2, eventType -> 2|>}], - testUnevaluated[pick2Generator[needSomethingForPicking[0], 0], {pick2Generator::missingParameters}], + testUnevaluated[typeTwoGenerator[systemWithParameterDependencies[], 0], {typeTwoGenerator::missingParameters}], VerificationTest[ - pick2Generator[needSomethingForPicking[0], 0, minSomething -> 2], - picked[{needSomethingForPicking[0], 0, <|minSomething -> 2, maxSomething -> Infinity, pickNumber -> 2|>}]], - - testUnevaluated[pick2Generator[minXorMax[0], 0], {pick2Generator::incompatibleSystem}], - testUnevaluated[pick2Generator[minXorMax[0], 0, pickNumber -> 2], {pick2Generator::incompatibleSystem}], - testUnevaluated[identityGenerator[minXorMax[0], 0], {identityGenerator::missingParameters}], - VerificationTest[identityGenerator[minXorMax[0], 0, minSomething -> 2], - {minXorMax[0], 0, <|minSomething -> 2, maxSomething -> Infinity|>}], - testUnevaluated[identityGenerator[minXorMax[0], 0, minSomething -> 2, maxSomething -> 3], - {identityGenerator::incompatibleParameters}], + typeTwoGenerator[systemWithParameterDependencies[], 0, minEventSize -> 2], + property[ + {systemWithParameterDependencies[], 0, <|minEventSize -> 2, maxEventSize -> Infinity, eventType -> 2|>}]], + + testUnevaluated[typeTwoGenerator[minXorMaxSystem[], 0], {typeTwoGenerator::incompatibleSystem}], + testUnevaluated[typeTwoGenerator[minXorMaxSystem[], 0, eventType -> 2], {typeTwoGenerator::incompatibleSystem}], + testUnevaluated[genericGenerator[minXorMaxSystem[], 0], {genericGenerator::missingParameters}], + VerificationTest[genericGenerator[minXorMaxSystem[], 0, minEventSize -> 2], + {minXorMaxSystem[], 0, <|minEventSize -> 2, maxEventSize -> Infinity|>}], + testUnevaluated[genericGenerator[minXorMaxSystem[], 0, minEventSize -> 2, maxEventSize -> 3], + {genericGenerator::incompatibleParameters}], (* Operator form *) - testUnevaluated[identityGenerator[echoSystem[0]] @ "test", {identityGenerator::argNotInit}], - testUnevaluated[identityGenerator[echoSystem[0], maxSomething -> 2] @ "test", {identityGenerator::argNotInit}], + testUnevaluated[genericGenerator[genericSystem[]] @ "test", {genericGenerator::argNotInit}], + testUnevaluated[genericGenerator[genericSystem[], maxEventSize -> 2] @ "test", {genericGenerator::argNotInit}], VerificationTest[ - identityGenerator[echoSystem[0]] @ 0, {echoSystem[0], 0, <|maxSomething -> Infinity, pickNumber -> None|>}], - testUnevaluated[identityGenerator[echoSystem[0]][], {identityGenerator::argx}], - testUnevaluated[identityGenerator[echoSystem[0]][0, 1], {identityGenerator::argx}], - VerificationTest[identityGenerator[echoSystem[0], maxSomething -> 2] @ 0, - {echoSystem[0], 0, <|maxSomething -> 2, pickNumber -> None|>}], - VerificationTest[identityGenerator[echoSystem[0], {maxSomething -> 2}] @ 0, - {echoSystem[0], 0, <|maxSomething -> 2, pickNumber -> None|>}], - VerificationTest[identityGenerator[echoSystem[0], <|maxSomething -> 2|>] @ 0, - {echoSystem[0], 0, <|maxSomething -> 2, pickNumber -> None|>}], - VerificationTest[identityGenerator[echoSystem[0], maxSomething -> 2, pickNumber -> 2] @ 0, - {echoSystem[0], 0, <|maxSomething -> 2, pickNumber -> 2|>}], + genericGenerator[genericSystem[]] @ 0, {genericSystem[], 0, <|maxEventSize -> Infinity, eventType -> None|>}], + testUnevaluated[genericGenerator[genericSystem[]][], {genericGenerator::argx}], + testUnevaluated[genericGenerator[genericSystem[]][0, 1], {genericGenerator::argx}], + VerificationTest[genericGenerator[genericSystem[], maxEventSize -> 2] @ 0, + {genericSystem[], 0, <|maxEventSize -> 2, eventType -> None|>}], + VerificationTest[genericGenerator[genericSystem[], {maxEventSize -> 2}] @ 0, + {genericSystem[], 0, <|maxEventSize -> 2, eventType -> None|>}], + VerificationTest[genericGenerator[genericSystem[], <|maxEventSize -> 2|>] @ 0, + {genericSystem[], 0, <|maxEventSize -> 2, eventType -> None|>}], + VerificationTest[genericGenerator[genericSystem[], maxEventSize -> 2, eventType -> 2] @ 0, + {genericSystem[], 0, <|maxEventSize -> 2, eventType -> 2|>}], VerificationTest[ - identityGenerator[listInit[0], {maxSomething -> 2}] @ 0, - {listInit[0], {maxSomething -> 2}, <|minSomething -> 0, maxSomething -> Infinity, pickNumber -> None|>}[0]], + genericGenerator[listStateSystem[], {maxEventSize -> 2}] @ 0, + {listStateSystem[], + {maxEventSize -> 2}, + <|minEventSize -> 0, maxEventSize -> Infinity, eventType -> None|>}[0]], VerificationTest[ - identityGenerator[listInit[0], {maxSomething -> 2}, minSomething -> 1] @ {0}, - {listInit[0], {maxSomething -> 2}, <|minSomething -> 1, maxSomething -> Infinity, pickNumber -> None|>}[{0}]], - VerificationTest[identityGenerator[listInit[0], minSomething -> 1, {maxSomething -> 2}] @ {0}, - {listInit[0], {0}, <|minSomething -> 1, maxSomething -> 2, pickNumber -> None|>}], + genericGenerator[listStateSystem[], {maxEventSize -> 2}, minEventSize -> 1] @ {0}, + {listStateSystem[], + {maxEventSize -> 2}, + <|minEventSize -> 1, maxEventSize -> Infinity, eventType -> None|>}[{0}]], + VerificationTest[genericGenerator[listStateSystem[], minEventSize -> 1, {maxEventSize -> 2}] @ {0}, + {listStateSystem[], {0}, <|minEventSize -> 1, maxEventSize -> 2, eventType -> None|>}], (* Existing generators *) VerificationTest[ - GenerateMultihistory[realSystem[0], 0], - {realSystem[0], 0, <|MaxDestroyerEvents -> Infinity, MaxEvents -> Infinity, MaxGeneration -> Infinity|>}], + GenerateMultihistory[realParameterSystem[], 0], + {realParameterSystem[], + 0, + <|MaxDestroyerEvents -> Infinity, MaxEvents -> Infinity, MaxGeneration -> Infinity|>}], VerificationTest[ - GenerateSingleHistory[realSystem[0], 0], - {realSystem[0], 0, <|MaxDestroyerEvents -> 1, MaxEvents -> Infinity, MaxGeneration -> Infinity|>}], + GenerateSingleHistory[realParameterSystem[], 0], + {realParameterSystem[], 0, <|MaxDestroyerEvents -> 1, MaxEvents -> Infinity, MaxGeneration -> Infinity|>}], (* Introspection *) VerificationTest[ - SubsetQ[$SetReplaceSystems, {echoSystem, needSomethingForPicking, minXorMax, listInit, realSystem}]], - VerificationTest[SubsetQ[$SetReplaceGenerators, {identityGenerator, pick2Generator}]], - VerificationTest[SetReplaceSystemParameters[listInit], {minSomething, maxSomething, pickNumber}] + SubsetQ[ + $SetReplaceSystems, + {genericSystem, systemWithParameterDependencies, minXorMaxSystem, listStateSystem, realParameterSystem}]], + VerificationTest[SubsetQ[$SetReplaceGenerators, {genericGenerator, typeTwoGenerator}]], + VerificationTest[SetReplaceSystemParameters[listStateSystem], {minEventSize, maxEventSize, eventType}] } |> |>