Main Content

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.

KeywordDescription
verify

Evaluates a logical expression and returns a pass, fail, or untested result. You can use optional arguments to label results in the Test Manager and Diagnostic Viewer or return an error message if a verify statement fails.

assert

Evaluates a logical expression and stops simulation if the expression evaluates to false. You can use optional arguments to return an error message in the Test Manager or Diagnostic Viewer.

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:

OperatorDescription
etThe 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 true if the specified time has elapsed since the beginning of the current test step.

before

Returns true until the specified time has elapsed from the beginning of the current test step.

duration

Returns the elapsed time for which the specified condition has been true. The elapsed time resets when the test step is re-entered or when the specified condition is no longer true.

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.

OperatorDescription
hasChanged

Returns true if the specified signal changes in value since the beginning of the test step, and otherwise returns false.

hasChangedFrom

Returns true if the specified signal changes from the specified value to a different value, and otherwise returns false.

hasChangedTo

Returns true if the specified signal changes to the specified value, and otherwise returns false.

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.

FunctionDescription
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 0 when the input is less than or equal to 0, and otherwise returns 1.

exp

Returns the natural exponential function, ex.

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.

OperationSyntaxDescriptionExample

Negation

~p

not p

verify(~p)

Conjunction

p && q

p and q

verify(p && q)

Disjunction

p || q

p or q

verify(p || q)

Implication

~p || q

if p, q. Logically equivalent to implication pq.

verify(~p || q)

Biconditional

(p && q) || (~p && ~q)

p and q, or not p and not q. Logically equivalent to biconditional pq.

verify((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 SyntaxDescriptionExample
x > yGreater thanverify(x > y)
x < yLess thanverify(x < y)
x >= yGreater than or equal toverify(x >= y)
x <= yLess than or equal toverify(x <= y)
x == yEqual toverify(x == y)
x ~= yNot equal toverify(x ~= y)

See Also

Topics