Define Test Steps and Assessments
You can assess your model simulation by creating test step actions, transitions, and assessments in Test Sequence and Test Assessment blocks
Test Sequence and Test Assessment blocks use MATLAB® as the action language. Steps and transitions can include strings, including string comparisons, as well as assessment statements, signal generation functions, and relational operators. For more information, see Test Assessment, Test Sequence, and Test Sequence Editor.
Assessment Statements
To verify simulation, stop simulation, and return verification results, use assessment statements.
Keyword | Description |
---|---|
verify | Evaluates a logical expression and
returns a |
assert | Evaluates a logical expression and
stops simulation if the expression evaluates to
|
Temporal Operators
To create an expression that evaluates the simulation time, use temporal operators. Variables in signal conditions must be inputs, parameters, or constants in the Test Sequence block. You can use these temporal operators:
Operator | Description |
---|---|
et | The elapsed time of the test step. You can specify the unit of time. If you do not specify a unit of time, the elapsed time is returned in seconds. |
t | The elapsed time of the simulation. You can specify the unit of time. If you do not specify a unit of time, the elapsed time is returned in seconds. |
after | Returns |
before | Returns |
duration | Returns the elapsed time for which
the specified condition has been |
Transition Operators
To create expressions that evaluate signal events, use transition operators. To evaluate signal events, the signals must be inputs in the Test Sequence or Test Assessment block.
Operator | Description |
---|---|
hasChanged | Returns |
hasChangedFrom | Returns |
hasChangedTo | Returns true if the specified signal
changes to the specified value, and otherwise returns
|
Signal Generation Functions
You can these functions in the Test Sequence block to create test signals, random number values, and natural exponents. You can use temporal operators with some signal generation functions. For more information, see Temporal Operators.
Note
Scaling, rounding, and other approximations of argument values can affect function outputs.
Function | Description |
---|---|
sin | Returns the sine of the input in radians. |
cos | Returns the cosine of the input argument in radians. |
square | Generates a square wave test signal. |
sawtooth | Generates a sawtooth wave test signal. |
triangle | Generates a triangle wave test signal |
ramp | Returns the value of the input. |
heaviside | Returns |
exp | Returns the natural exponential function, . |
rand | Returns uniformly distributed pseudorandom values. |
randn | Returns normally distributed pseudorandom values. |
latch | Saves the value of the input and returns the saved value. Resets the saved value when the step exits and reevaluates when the step is next active. |
Logical Operators
You can use logical connectives in actions, transitions, and
assessments. In these examples, p
and q
represent
Boolean signals or logical expressions.
Operation | Syntax | Description | Example |
---|---|---|---|
Negation | ~p | not |
|
Conjunction | p && q |
|
|
Disjunction | p || q |
|
|
Implication | ~p || q | if |
|
Biconditional | (p && q) || (~p && ~q) |
|
|
Relational Operators
You can use relational operators in actions, transitions, and
assessments. In these examples, x
and y
represent
numeric-type variables.
Using ==
or ~=
operators
in a verify
statement returns a warning when comparing
floating-point data. Consider the precision limitations associated
with floating-point numbers when implementing verify
statements.
See Floating-Point Numbers.
If you use floating-point data, consider defining a tolerance for
the assessment. For example, instead of verify(x == 5)
,
verify x
within a tolerance of 0.001
:
verify(abs(x-5) < 0.001)
Operator and Syntax | Description | Example |
---|---|---|
x > y | Greater than | verify(x > y) |
x < y | Less than | verify(x < y) |
x >= y | Greater than or equal to | verify(x >= y) |
x <= y | Less than or equal to | verify(x <= y) |
x == y | Equal to | verify(x == y) |
x ~= y | Not equal to | verify(x ~= y) |