Main Content

assumeSignalsMatch

Class: sltest.TestCase
Package: sltest

Assume two data sets are equivalent

Description

example

assumeSignalsMatch(testCase,actual,expected) assumes that the actual and expected signal data values are equivalent. When an assumption fails, the test stops running at the test point or test file, and the test is marked as incomplete. For more information, see matlab.unittest.qualifications.Assumable.

example

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

example

assumeSignalsMatch(___,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 assumption that the actual and expected values are equivalent fails, specified as a string, character array, a function handle, or an instance of a matlab.unittest.diagnostics.Diagnostic class.

Example: 'Simulation output does not match.'

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

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 assumeSignalsMatch to compare the values.

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

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

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

testCase.assumeSignalsMatch(actual,'baseline.mat',...
   'AbsTol',1e-12)
 

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

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