TestCreate
TestCreate[input]
create a TestObject to determine whether input evaluates to True.
TestCreate[input,expected]
create a TestObject to determine whether input evaluates to expected.
TestCreate[input,expected,messages]
create a TestObject that is expected to generate the list of message names messages.
Details and Options
- TestCreate returns a TestObject.
- TestCreate has attribute HoldAllComplete, therefore it does not immediately evaluate input or expected.
- Use TestReport or TestEvaluate to run a test created by TestCreate.
- TestCreate has the following options:
-
MemoryConstraint Infinity memory (in bytes) the test is allowed to use MetaInformation < > extra information associated with the test SameTest SameQ function to compare actual and expected output TestID Automatic unique identifier for the test TimeConstraint Infinity time (in seconds) the test is allowed to use - TestIDAutomatic creates a unique ID by doing a hash of the test expression.
Examples
open allclose allBasic Examples (4)
Create a test that tests whether the input evaluates to True:
Test whether the input evaluates to the expected output:
When a test fails, it returns an outcome of Failure:
When the input evaluates to the expected output but gives messages, the outcome is MessagesFailure:
Scope (2)
Basic Uses (2)
Perform a test and present the results in a Dataset:
Test if the results of an NIntegrate are numerically equivalent to Integrate by using an absolute tolerance:
This can also be done by using the SameTest option:
Options (13)
SameTest (5)
Test whether the input is an integer:
Test if the absolute precision of the input is at least 10-12:
Test if the relative precision is at least 10-5:
Test if two expressions are equivalent after simplification:
Use Unevaluated to pass unevaluated expressions to the SameTest function:
You can use a combination of Function and Echo to print the arguments of the SameTest function:
TestID (4)
Add a TestID to the test:
A TestID can be any expression:
By default, the TestID is a Hash of the test:
The TestID will change if the input of the TestCreate expression is different:
Use CreateUUID to create random identifiers every time:
MetaInformation (2)
Store arbitrary metainformation in the TestObject:
Access the stored MetaInformation:
MetaInformation can be any expression:
Possible Issues (3)
The expected output is evaluated before comparison with the actual output:
Use Unevaluated to compare expressions before evaluation happens:
Messages generated on evaluation of expected output are not accounted for in the expected messages:
If SameTest does not evaluate to True or False, a failure type of "SameTestUnevaluated" is reported:
Text
Wolfram Research (2023), TestCreate, Wolfram Language function, https://reference.wolfram.com/language/ref/TestCreate.html.
CMS
Wolfram Language. 2023. "TestCreate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TestCreate.html.
APA
Wolfram Language. (2023). TestCreate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TestCreate.html