MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
end
function finiteCheck(testCase,Data)
import matlab.unittest.constraints.IsFinite
act = cleanData(Data);
testCase.verifyThat(act,IsFinite)
end
function noZeroCheck(testCase,Data)
import matlab.unittest.constraints.EveryElementOf
import matlab.unittest.constraints.IsEqualTo
act = cleanData(Data);
testCase.verifyThat(EveryElementOf(act),~IsEqualTo(0))
end
end
end

Create and run a parameterized test suite. View the results. The framework runs the
eight parameterized tests using the data defined in the test file.

import matlab.unittest.TestSuite
suite1 = TestSuite.fromClass(?TestClean);
results = suite1.run;
table(results)

Running TestClean
........
Done TestClean
__________

ans =

8×6 table

Name Passed Failed Incomplete Duration Details
___________________________________________ ______ ______ __________ _________ ____________

'TestClean/classCheck(Data=clean)' true false false 0.27887 [1×1 struct]
'TestClean/classCheck(Data=needsCleaning)' true false false 0.0069881 [1×1 struct]
'TestClean/sortCheck(Data=clean)' true false false 0.0046028 [1×1 struct]
'TestClean/sortCheck(Data=needsCleaning)' true false false 0.0035363 [1×1 struct]
'TestClean/finiteCheck(Data=clean)' true false false 0.023965 [1×1 struct]
'TestClean/finiteCheck(Data=needsCleaning)' true false false 0.0024557 [1×1 struct]
'TestClean/noZeroCheck(Data=clean)' true false false 0.7077 [1×1 struct]

33 Unit Testing

Free download pdf