Test Sequence and Assessment Syntax
This topic describes syntax used within Test Sequence and Test Assessment blocks, and Stateflow^{®} charts. In the blocks, you use this syntax for test step actions, transitions, and assessments. In charts, you use this syntax in states and transitions.
Test Sequence and Test Assessment blocks use MATLAB^{®} as the action language. You can also use strings, including string
comparisons, in test sequence steps and transitions. You define actions, transitions,
assessments with assessment operators, temporal operators, transition operators, signal
generation functions, logical operators, and relational operators. Except for
verify
, Stateflow charts can use
all operators in MATLAB or C as the action language. verify
can be used only with
MATLAB language and you cannot use strings in verify
statements. For
example:
To output a square wave with a period of
10
sec:square(et/10)
To transition when
h
changes to0
:hasChangedTo(h,0)
To verify that x is greater than y:
verify(x > y)
Assessment Statements
To verify simulation, stop simulation, and return verification results, use assessment statements.
Keyword  Statement Syntax  Description  Example 

verify 
 Assesses a logical expression. Optional arguments label results in the Test Manager and diagnostic viewer.  verify(x > y,... 'SimulinkTest:greaterThan',... 'x and y values are %d, %d',... x,y) 
assert 
 Evaluates a logical expression. Failure stops simulation and returns an error. Optional arguments return an error message.
 assert(h==0 && k==0,... 'h and k must '... 'initialize to 0') 
Syntax in the table uses these arguments:
Temporal Operators
To create an expression that evaluates the simulation time, use temporal operators. Variables used in signal conditions must be inputs, parameters, or constants in the Test Sequence block.
Operator  Syntax  Description  Example 

et 
 The elapsed time of the test step in  The elapsed time of the test sequence step in milliseconds: et(msec) 
t 
 The elapsed time of the simulation in  The elapsed time of the simulation in microseconds: t(usec) 
after 
 Returns  After 4 seconds: after(4,sec) 
before 
 Returns  Before 4 seconds: before(4,sec) 
duration 
 Returns  Return duration(Phi>1,msec) > 550 
Syntax in the table uses these arguments:
Transition Operators
To create expressions that evaluate signal events, use transition operators. Common transition operators include:
Operator  Syntax  Description  Example 

hasChanged  hasChanged(u)  Returns
 Transition when hasChanged(h) 
hasChangedFrom  hasChangedFrom(u,A)  Returns true if
 Transition when hasChangedFrom(h,1) 
hasChangedTo  hasChangedTo(u,B)  Returns true if
 Transition when hasChangedTo(h,0) 
Signal Generation Functions
The following table lists common functions you can use in the Test Sequence block to
create test signals, random number values, and natural exponents. It also describes the
latch
function, which saves and returns a specific value evaluated
within a test sequence step. For more information about each function, click its name in the
first column.
Some signal generation functions use the temporal operator et
, which is
the elapsed time of the test step in seconds. For additional operators related to
et
that you can use in test sequence steps, see Temporal Operators.
Note
Scaling, rounding, and other approximations of argument values can affect function outputs.
Function  Syntax  Description  Example 

sin  sin(x)  Returns the sine of  A sine wave with a period of 10 sec: sin(et*2*pi/10) 
cos  cos(x)  Returns the cosine of  A cosine wave with a period of 10 sec: cos(et*2*pi/10) 
square  square(x)  Square wave output with a period of Within
the interval
 Output a square wave with a period of square(et/10) 
sawtooth  sawtooth(x)  Sawtooth wave output with a period of Within
the interval
 Output a sawtooth wave with a period of sawtooth(et/10) 
triangle  triangle(x)  Triangle wave output with a period of Within
the interval
 Output a triangle wave with a period of triangle(et/10) 
ramp  ramp(x)  Ramp signal of slope
 Ramp one unit for every 5 seconds of test step elapsed time: ramp(et/5) 
heaviside  heaviside(x)  Heaviside step signal, returning
 Output a heaviside signal after heaviside(et5) 
exp  exp(x)  Returns the natural exponential function, $${e}^{x}$$.  An exponential signal progressing at one tenth of the test step elapsed time: exp(et/10) 
rand  rand  Uniformly distributed pseudorandom values  Generate new random values for each simulation by declaring
coder.extrinsic('rand')
nr = rand
sg = a + (ba)*nr 
randn  randn  Normally distributed pseudorandom values  Generate new random values for each simulation by declaring
coder.extrinsic('randn')
nr = randn
sg = nr*2 
latch  latch(x)  Saves the value of
 Latch b = latch(torque) 
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
numerictype variables.
Using ==
or ~=
operators
in a verify
statement returns a warning when comparing
floatingpoint data. Consider the precision limitations associated
with floatingpoint numbers when implementing verify
statements.
See FloatingPoint Numbers.
If you use floatingpoint 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(x5) < 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) 