Class TestEvoLudo
Object
TestEvoLudo
- All Implemented Interfaces:
RunListener
TestEvoLudo is a test suite for EvoLudo. It generates test cases from a
generator file or directory and compares the results with reference files.
The test suite can be run in two modes: (1) generating test cases from a
generator file or directory, and (2) testing the generated or existing test
cases. The test suite accepts the following command line options:
--generate <filename>: read option sets from file and generate test cases--tests <directory>: directory for storing/retrieving test cases (defaults to references)--references <directory>: directory for storing/retrieving test cases--reports <directory>: directory for storing failed test reports--compress: compress generated test files--minor: dump differences for minor failures--verb: verbose mode--help,-hor no arguments: this help screen
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enumThe control codes for changing the style of the console output. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) booleanThe flag to indicate whether to dump differences for minor failures.(package private) EvoLudoJREPointer to engine.(package private) FileDirectory with generator scripts for tests.(package private) booleanThe flag to indicate whether tests are running.(package private) LoggerLogger for keeping track of and reporting events and issues.(package private) intThe number of failed tests.(package private) intThe number of tests failing with minor errors.(package private) intThe total number of tests.(package private) intThe number of tests with warnings.(package private) PrintStreamThe output stream for logging messages.(package private) booleanThe flag to indicate whether to perform tests or generate test cases.(package private) FileDirectory with reference results.(package private) FileDirectory for storing reports of failed tests.(package private) static final Collection<String> List of keys to exclude from test case comparisons.(package private) static final StringThe prefix to mark the beginning of the SHA hash in the filename.(package private) booleanThe flag to indicate whether to skip SHA checks.(package private) FileDirectory containing tests or for storing generated tests.(package private) booleanThe flag to indicate whether to use compression for the generated test files.(package private) booleanThe flag to indicate whether to run in verbose mode. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate FilecheckReference(File references, Plist result, String refbasename) Search for reference file with the name baserefbasename(no SHA, no extensions) in directoryreferences.private booleancompareRuns(File refname, Plist reference, Plist replicate) Compare reference outputreferencewith the output of the testreplicateand generate a report if differences are found.voidgenerate()Generate test cases from generator file or directory.protected voidGenerate test cases from generator fileclo.private StringgenerateBasename(String clo, int idx) Generate the base name for tests from command line optionscloand indexidx.static StringhashSHA256(Object obj) Compute SHA-256 hash of serializable objectobj.voidhelp()Print help screen.voidLog error message in red color to console or logger.voidlogMessage(String msg) Log message to console or logger.voidLog message in green color to console or logger.voidLog bold message to console or logger.voidlogWarning(String msg) Log warning message in yellow color to console or logger.static voidEntry point for test routines of EvoLudo.voidCalled after a running EvoLudo model stopped because the model converged (or reached an absorbing state).voidParse the command line options.booleanrun()Generate or run all tests.private booleanLoad and run module with parametersclo.private static FileRecursively search for a file whose name starts withsearchin directoryfile.static Stringsha256(Plist plist, Collection<String> exclude) Compute the SHA-256 hash of theplist, excluding the keys inexclude.private StringstripExport(String clo) Strip export option from command line optionsclo.voidTest all files in directorydir.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RunListener
modelDidInit, modelDidReset, modelRelaxed, modelRunning, modelSettings
-
Field Details
-
SHA_EXCLUDE
List of keys to exclude from test case comparisons. -
SHA_PREFIX
The prefix to mark the beginning of the SHA hash in the filename.- See Also:
-
engine
EvoLudoJRE enginePointer to engine. Engine has EvoLudoJRE class but do not rely on JRE specifics. -
logger
Logger loggerLogger for keeping track of and reporting events and issues. -
output
PrintStream outputThe output stream for logging messages. -
testsDir
File testsDirDirectory containing tests or for storing generated tests. -
reportsDir
File reportsDirDirectory for storing reports of failed tests. -
referencesDir
File referencesDirDirectory with reference results. -
generator
File generatorDirectory with generator scripts for tests. -
performTest
boolean performTestThe flag to indicate whether to perform tests or generate test cases. -
isRunning
boolean isRunningThe flag to indicate whether tests are running. -
useCompression
boolean useCompressionThe flag to indicate whether to use compression for the generated test files. -
dumpMinor
boolean dumpMinorThe flag to indicate whether to dump differences for minor failures. -
verbose
boolean verboseThe flag to indicate whether to run in verbose mode. -
skipSHA
boolean skipSHAThe flag to indicate whether to skip SHA checks. -
nTests
int nTestsThe total number of tests. -
nTestFailures
int nTestFailuresThe number of failed tests. -
nTestMinor
int nTestMinorThe number of tests failing with minor errors. -
nTestWarnings
int nTestWarningsThe number of tests with warnings.
-
-
Constructor Details
-
TestEvoLudo
public TestEvoLudo()Constructor for TestEvoLudo.
-
-
Method Details
-
generate
public void generate()Generate test cases from generator file or directory. -
generate
Generate test cases from generator fileclo.- Parameters:
clo- the generator file
-
test
Test all files in directorydir. This directory can either contain test files or files for generating them. In either case the test output is compared to the reference files.- Parameters:
dir- the directory with test files
-
sha256
Compute the SHA-256 hash of theplist, excluding the keys inexclude.- Parameters:
plist- the property list to hashexclude- the keys to exclude from the hash- Returns:
- the SHA-256 hash as a hexadecimal string
-
hashSHA256
Compute SHA-256 hash of serializable objectobj.- Parameters:
obj- the object to hash- Returns:
- the SHA-256 hash as a hexadecimal string
- Throws:
IOException- if an I/O error occursNoSuchAlgorithmException- if SHA-256 is not supported
-
generateBasename
-
stripExport
-
runModule
Load and run module with parametersclo. The options--seed 0is prepended and--delay 0is appended toclo. Because for options that are specified multiple times the latter takes precedence, this ensures that the results are reproducible with potentially custom seeds and also run at full speed. Returnsfalseif the module didn't run and hence no export was generated, even if requested with the--exportoption. This happens for example with--timestop 0.- Parameters:
task- the task that is running (generating or testing)clo- the command line options for running the module- Returns:
trueif the module ran successfully
-
compareRuns
Compare reference outputreferencewith the output of the testreplicateand generate a report if differences are found. The reference is stored inrefname. The method returnstrueif the test passed.- Parameters:
refname- the name of the reference filereference- the referencePlistreplicate- the replicatePlist- Returns:
trueif the test passed
-
checkReference
Search for reference file with the name baserefbasename(no SHA, no extensions) in directoryreferences. Ifrefbasenameis found verify the results in the plistresult.- Parameters:
references- the directory with reference filesresult- thePlistwith the resultsrefbasename- the base name of the reference file (if it exists)- Returns:
- if verification successful return
Filepointing to reference; if unsuccesssful returnnull; and if reference file not found returnreferences
-
search
-
modelStopped
public void modelStopped()Description copied from interface:RunListenerCalled after a running EvoLudo model stopped because the model converged (or reached an absorbing state).- Specified by:
modelStoppedin interfaceRunListener
-
run
public boolean run()Generate or run all tests.- Returns:
trueif successful
-
parse
Parse the command line options.- Parameters:
args- the command line options
-
help
public void help()Print help screen. -
main
Entry point for test routines of EvoLudo.- Parameters:
args- the string of command line arguments
-
logMessage
Log message to console or logger.- Parameters:
msg- the message to log
-
logTitle
Log bold message to console or logger.- Parameters:
msg- the message to log
-
logOk
Log message in green color to console or logger.- Parameters:
msg- the message to log
-
logWarning
Log warning message in yellow color to console or logger.- Parameters:
msg- the warning to log
-
logError
Log error message in red color to console or logger.- Parameters:
msg- the error to log
-