matlabtest.compiler.TestCase.assumeExecutionMatchesMATLAB - Assume that deployed code artifact execution results match MATLAB results - MATLAB (original) (raw)
Class: matlabtest.compiler.TestCase
Namespace: matlabtest.compiler
Assume that deployed code artifact execution results match MATLAB results
Since R2023a
Syntax
Description
assumeExecutionMatchesMATLAB([testCase](#mw%5F964e6c00-1a73-4b82-9c2d-e05fa16f51a0%5Fsep%5Fmw%5F749a5a23-a3ff-402c-a105-186d6548ef7c),[executionResults](#mw%5F964e6c00-1a73-4b82-9c2d-e05fa16f51a0%5Fsep%5Fmw%5F8619280e-6975-4890-b417-c1a12ee1fc62))
assumes that the execution results specified by executionResults
for the deployed code artifact generated by MATLAB® Compiler SDK™ match the execution of the MATLAB source code in the equivalence test case testCase
.
assumeExecutionMatchesMATLAB([testCase](#mw%5F964e6c00-1a73-4b82-9c2d-e05fa16f51a0%5Fsep%5Fmw%5F749a5a23-a3ff-402c-a105-186d6548ef7c),[executionResults](#mw%5F964e6c00-1a73-4b82-9c2d-e05fa16f51a0%5Fsep%5Fmw%5F8619280e-6975-4890-b417-c1a12ee1fc62),[diagnostic](#mw%5F964e6c00-1a73-4b82-9c2d-e05fa16f51a0%5Fsep%5Fmw%5F2675f0f8-07e5-4f3b-9263-aa2d6a68c126))
returns diagnostic information specified by diagnostic
.
assumeExecutionMatchesMATLAB(___,[Name=Value](#namevaluepairarguments))
specifies options using one or more name-value arguments in addition to the input arguments in previous syntaxes.
Input Arguments
Failure diagnostic information, specified as a:
- String scalar or character vector
- Function handle
- matlab.automation.diagnostics.Diagnostic object or object of one of its subclasses
Example: verifyExecutionMatchesMATLAB(testCase,executionResults,"Equivalence test failed")
Name-Value Arguments
Specify optional pairs of arguments asName1=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.
Example: AbsTol=0.01
Absolute tolerance, specified as a numeric array. The sizes of AbsTol
andexpected
, where expected
is the output of the MATLAB execution of the function, must be the same or compatible. See Compatible Array Sizes for Basic Operations for more information about compatible arrays.
The tolerance is applied only to values of the same data type. For an absolute tolerance to be satisfied, abs(expected-actual) <= AbsTol
must betrue
, where actual
is [ExecutableOutput](matlabtest.compiler.results.executionresults-class.html#mw%5F0b1ee524-966a-487a-aa9e-f4e18dd935da)
.
Relative tolerance, specified as a numeric array. The sizes of RelTol
andexpected
, where expected
is the output of the MATLAB execution of the function, must be the same or compatible. See Compatible Array Sizes for Basic Operations for more information about compatible arrays.
The tolerance is applied only to values of the same data type. For a relative tolerance to be satisfied, abs(expected-actual) <= RelTol.*abs(expected)
must betrue
, where actual
is [ExecutableOutput](matlabtest.compiler.results.executionresults-class.html#mw%5F0b1ee524-966a-487a-aa9e-f4e18dd935da)
.
Examples
This example shows how to generate a Python® package from MATLAB source code and test for equivalence by using assumptions.
Suppose that you want to generate a Python package for a function called makesquare
, which generates an _n_-by-n matrix:
function y = makesquare(x) y = magic(x); end
This class definition file defines an equivalence test case that inherits frommatlabtest.compiler.TestCase
. The test case in themethods
block defines a test case that:
- Builds the Python package from the
makesquare
function - Executes the Python package with input set to
5
- Assumes that the execution of the Python package matches the execution of the MATLAB function
makesquare
with the same input
classdef tDeployment < matlabtest.compiler.TestCase methods(Test) function pythonEquivalence(testCase) buildResults = build(testCase,"makesquare.m", ... "pythonPackage"); executionResults = execute(testCase,buildResults,{5}); assumeExecutionMatchesMATLAB(testCase,executionResults); end end end
Run the pythonEquivalence
test.
runtests("tDeployment", ... ProcedureName="pythonEquivalence")
Running pythonEquivalence .. Done pythonEquivalence
ans =
TestResult with properties:
Name: 'tDeployment/pythonEquivalence'
Passed: 1
Failed: 0
Incomplete: 0
Duration: 93.1237
Details: [1×1 struct]
Totals: 1 Passed, 0 Failed, 0 Incomplete. 93.1237 seconds testing time.
This example shows how to generate a Python package from MATLAB source code and test for equivalence by using assumptions, and return a custom diagnostic result.
Suppose that you want to generate a Python package for a function called makesquare
, which generates an _n_-by-n matrix:
function y = makesquare(x) y = magic(x); end
This class definition file defines an equivalence test case that inherits frommatlabtest.compiler.TestCase
. The test case in themethods
block defines a test case that:
- Builds the Python package from the
makesquare
function - Executes the Python package with input set to
5
- Assumes that the execution of the Python package matches the execution of the MATLAB function
makesquare
with the same input and returns a string if the test fails
classdef tDeployment < matlabtest.compiler.TestCase methods(Test) function pythonEquivalence(testCase) buildResults = build(testCase,"makesquare.m", ... "pythonPackage"); executionResults = execute(testCase,buildResults,{5}); d = "Equivalence test failed."; assumeExecutionMatchesMATLAB(testCase,executionResults,d); end end end
Run the pythonEquivalence
test.
runtests("tDeployment", ... ProcedureName="pythonEquivalence")
Running pythonEquivalence .. Done pythonEquivalence
ans =
TestResult with properties:
Name: 'tDeployment/pythonEquivalence'
Passed: 1
Failed: 0
Incomplete: 0
Duration: 93.1237
Details: [1×1 struct]
Totals: 1 Passed, 0 Failed, 0 Incomplete. 93.1237 seconds testing time.
This example shows how to generate a Python package from MATLAB source code and test for equivalence by using assumptions with tolerances.
Suppose that you want to generate a Python package for a function called makesquare
, which generates an _n_-by-n matrix:
function y = makesquare(x) y = magic(x); end
This class definition file defines an equivalence test case that inherits frommatlabtest.compiler.TestCase
. The test case in themethods
block defines a test case that:
- Builds the Python package from the
makesquare
function - Executes the Python package with input set to
5
- Assumes that the execution of the Python package matches the execution of the MATLAB function
makesquare
with the same input within an absolute tolerance of0.001
classdef tDeployment < matlabtest.compiler.TestCase methods(Test) function pythonEquivalence(testCase) buildResults = build(testCase,"makesquare.m", ... "pythonPackage"); executionResults = execute(testCase,buildResults,{5}); assumeExecutionMatchesMATLAB(testCase,executionResults, ... AbsTol=0.001); end end end
Run the pythonEquivalence
test.
runtests("tDeployment", ... ProcedureName="pythonEquivalence")
Running pythonEquivalence .. Done pythonEquivalence
ans =
TestResult with properties:
Name: 'tDeployment/pythonEquivalence'
Passed: 1
Failed: 0
Incomplete: 0
Duration: 93.1237
Details: [1×1 struct]
Totals: 1 Passed, 0 Failed, 0 Incomplete. 93.1237 seconds testing time.
Limitations
- You cannot generate deployed code artifacts or test them for equivalence in MATLAB Online™.
Version History
Introduced in R2023a
See Also
Classes
- matlabtest.compiler.TestCase | matlabtest.compiler.results.ExecutionResults | matlab.unittest.qualifications.Assumable
Functions
- build | execute | verifyExecutionMatchesMATLAB | assertExecutionMatchesMATLAB | fatalAssertExecutionMatchesMATLAB