matlabtest.compiler.TestCase.verifyExecutionMatchesMATLAB - Verify that deployed code artifact execution results match MATLAB results - MATLAB (original) (raw)
Class: matlabtest.compiler.TestCase
Namespace: matlabtest.compiler
Verify that deployed code artifact execution results match MATLAB results
Since R2023a
Syntax
Description
verifyExecutionMatchesMATLAB([testCase](#mw%5F83561bcf-d1f7-4c51-96d8-7872e73c9007%5Fsep%5Fmw%5F749a5a23-a3ff-402c-a105-186d6548ef7c),[executionResults](#mw%5F83561bcf-d1f7-4c51-96d8-7872e73c9007%5Fsep%5Fmw%5F8619280e-6975-4890-b417-c1a12ee1fc62))
verifies 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
.
verifyExecutionMatchesMATLAB([testCase](#mw%5F83561bcf-d1f7-4c51-96d8-7872e73c9007%5Fsep%5Fmw%5F749a5a23-a3ff-402c-a105-186d6548ef7c),[executionResults](#mw%5F83561bcf-d1f7-4c51-96d8-7872e73c9007%5Fsep%5Fmw%5F8619280e-6975-4890-b417-c1a12ee1fc62),[diagnostic](#mw%5F83561bcf-d1f7-4c51-96d8-7872e73c9007%5Fsep%5Fmw%5F2675f0f8-07e5-4f3b-9263-aa2d6a68c126))
returns diagnostic information specified by diagnostic
.
verifyExecutionMatchesMATLAB(___,[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 MATLAB Compiler SDK.
The function makesquare
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 from matlabtest.compiler.TestCase
. The test case in the methods
block defines a test case that:
- Builds the Python package from the
makesquare
function - Executes the Python package with input set to
5
- Verifies the execution of the Python package against 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}); verifyExecutionMatchesMATLAB(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 MATLAB Compiler SDK, and return a custom diagnostic result.
The function makesquare
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
- Verifies the execution of the Python package against 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."; verifyExecutionMatchesMATLAB(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 MATLAB Compiler SDK.
The function makesquare
generates an_n_-by-n matrix and the functionmyAdd
takes two inputs and adds them together:
function y = makesquare(x) y = magic(x); end
function y = myAdd(a,b) y = a + b; end
This class definition file:
- Builds a packaged that contains
makesquare
andmyAdd
- Saves the build results object if the test fails
- Verifies the result with an absolute tolerance
classdef tDeployment < matlabtest.compiler.TestCase
methods(Test)
function pythonEquivalence(testCase)
functionsToDeploy = ["makesquare.m","myAdd.m"];
buildResults = build(testCase,functionsToDeploy, ...
"pythonPackage",PreservingOnFailure=true);
preserveOnFailure=true;
executionResults = execute(testCase,buildResults,{5}, ...
"makesquare",PreservingOnFailure=preserveOnFailure);
verifyExecutionMatchesMATLAB(testCase,executionResults, ...
AbsTol=0.0001);
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.Verifiable
Functions
- build | execute | assumeExecutionMatchesMATLAB | assertExecutionMatchesMATLAB | fatalAssertExecutionMatchesMATLAB