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.
For information on using the commandline interface to create and edit test sequence steps, transitions, and data symbols, see the functions listed under Test Sequences on the Test Scripts page.
Test Sequence and Test Assessment blocks use MATLAB^{®} as the action language. 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. For example:
To output a square wave with a period of 10
sec:
square(et/10)
To transition when h
changes to 0
:
hasChangedTo(h,0)
To verify that x is greater than y:
verify(x > y)
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:
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:
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) 
Some signal generation functions use the temporal operator et
, which is the
elapsed time of the test step in seconds. Scaling, rounding, and other approximations of
argument values can affect function outputs. Common
signal generation functions include:
Function  Syntax  Description  Example 

square  square(x)  Represents a square wave output with a period of Within
the interval
 Output a square wave with a period of square(et/10) 
sawtooth  sawtooth(x)  Represents a sawtooth wave output with a period of Within
the interval
 Output a sawtooth wave with a period of sawtooth(et/10) 
triangle  triangle(x)  Represents a triangle wave output with a period of Within
the interval
 Output a triangle wave with a period of triangle(et/10) 
ramp  ramp(x)  Represents a ramp signal of slope
 Ramp one unit for every 5 seconds of test step elapsed time: ramp(et/5) 
heaviside  heaviside(x)  Represents a heaviside step signal, returning
 Output a heaviside signal after heaviside(et5) 
latch  latch(x)  Saves the value of
 Latch b = latch(torque) 
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) 
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 
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) 
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) 


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) 