Main Content

assertSignalsMatch

Class: sltest.TestCase
Namespace: sltest

Assert two data sets are equivalent

Since R2020b

Description

example

assertSignalsMatch(testCase,actual,expected) filters test content by asserting that the actual and expected signal data values are equivalent. When an assertion fails, the test point or test file stops running, and that test is marked as failed. This qualification is useful when a failure at the assertion point renders the rest of the current test method invalid, but does not prevent proper execution of other test methods. Often, you use assertions to check that preconditions of the current test are not violated or that fixtures are set up correctly. For more information, see matlab.unittest.qualifications.Assertable.

example

assertSignalsMatch(___,diagnostic) returns diagnostic information when the actual and expected data values are not equivalent.

example

assertSignalsMatch(___,Name,Value) filters test content with additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all

Instance of the test case, specified as an sltest.TestCase object.

Actual values to compare to expected values, specified as time series data, a string, or character array. The data for each actual value must pair data value with time value. The data must be in a format supported by the Simulation Data Inspector. The Simulation Data Inspector requires data in a format that associates sample values with time. Supported formats include timeseries, Structure with time, and Dataset.

Example: 'C:/matlab/data/actualData.mat'

Expected values to use as the baseline for the comparison. The data for each expected value must pair data value with time value. The data must be in a format supported by the Simulation Data Inspector. The Simulation Data Inspector requires data in a format that associates sample values with time. Supported formats include timeseries, Structure with time, and Dataset.

Example: 'C:/matlab/data/expectedData.mat'

Diagnostic information to display when the assertion that the actual and expected values are equivalent fails, specified as a string, character array, a function handle, or an instance of a matlab.automation.diagnostics.Diagnostic class.

Example: 'Simulation output does not match.'

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'AbsTol',.02

In addition to the listed Name-Value pairs, you can use the Simulink.sdi.constraints.MatchesSignal Name-Value pairs.

Absolute tolerance, specified as the comma-separated pair consisting of 'AbsTol' and the scalar value of the tolerance. The tolerance specifies the magnitude of the difference between the actual and expected values.

Example: 'AbsTol',1e-9

Relative tolerance, specified as the comma-separated pair consisting of 'RelTol' and the scalar value of the tolerance. The relative tolerance specifies the magnitude of the difference between the actual and expected values, relative to the expected value.

Example: 'RelTol',.002

Time tolerance, specified as the comma-separated pair consisting of 'TimeTol' and the scalar value of the tolerance.

Example: 'TimeTol',.2

Attributes

Accesspublic
Sealedtrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Create a test case for interactive use. Then, simulate the model in normal mode to obtain the expected values, and simulate in rapid accelerator mode to obtain the actual values. Use assertSignalsMatch to compare the values.

testCase =...
   sltest.TestCase.forInteractiveUse;
 
expected = testCase.simulate('myModel',...
   'SimulationMode','Normal');
actual = testCase.simulate('myModel',...
   'SimulationMode','Rapid-Accelerator');
 
testCase.assertSignalsMatch(actual,expected)

Create a test case for interactive use. Simulate the model in rapid accelerator mode to obtain the actual values. Use assertSignalsMatch to compare the actual values to the baseline values saved in a MAT-file. Set a relative tolerance.

testCase =...
   sltest.TestCase.forInteractiveUse;
 
actual = testCase.simulate('myModel',...
   'SimulationMode','Rapid-Accelerator');

testCase.assertSignalsMatch(actual,'baseline.mat',...
   'RelTol',0.001)
 

Create a test case for interactive use. Then, simulate the model in rapid accelerator mode to obtain the actual values. Use assertSignalsMatch to compare the actual values to the baseline values saved in a MAT-file. Specify the diagnostic message to display if the assertion fails.

testCase =...
   sltest.TestCase.forInteractiveUse;
 
actual = testCase.simulate('myModel',...
   'SimulationMode','Rapid-Accelerator');
 
testCase.assertSignalsMatch(actual,'baseline.mat',...
   'Rapid-Accel output did not match.')
 

Version History

Introduced in R2020b