specifies a tag that will be used to identify the assertion if it fails.
- Assertions are often placed in code to describe and check assumptions made by the programmer.
- By default, assertions are disabled in an ordinary Wolfram Language session, but are enabled in the Wolfram System debugger.
- On[Assert] enables assertions in a Wolfram Language session, and causes a message to be generated whenever an assertion fails.
- When Assert appears in a file, the name of the file and the line number at which it appears are by default automatically used as tags for the assertion.
- In the Wolfram Language debugger, the failure of an assertion by default generates a breakpoint.
- $AssertFunction gives a function to be applied to Assert[test,…] when test does not evaluate to True.
Basic Examples (3)
When assertions are enabled with On, a message is produced:
This shows how the line information and package name are stored in the Assert expression:
You can change the behavior when an assertion fails by assigning to $AssertFunction. This function throws an exception when an assertion fails:
Wolfram Research (2010), Assert, Wolfram Language function, https://reference.wolfram.com/language/ref/Assert.html.
Wolfram Language. 2010. "Assert." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Assert.html.
Wolfram Language. (2010). Assert. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Assert.html