MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

At the command prompt, create a test case for interactive testing.


import matlab.unittest.TestCase
import matlab.unittest.constraints.HasLength


testCase = TestCase.forInteractiveUse;


Test a passing case.


testCase.verifyThat(zeros(5), HasLength(5) | ~HasSameSizeAs(repmat(1,5)))


Interactive verification passed.


The test passes because one of the or conditions, HasLength(5), is true.


Test a failing case.


testCase.verifyThat(zeros(5), HasLength(5) & ~HasSameSizeAs(repmat(1,5)))


Interactive verification failed.




Framework Diagnostic:


AndConstraint failed.
--> + [First Condition]:
| HasLength passed.
--> AND



  • [Second Condition]:
    | Negated HasSameSizeAs failed.
    | Size [5 5] of Actual Value and Expected Value were the same but should not have been.
    -+---------------------


The test fails because one of the and conditions, ~HasSameSizeAs(repmat(1,5)), is
false.


See Also


matlab.unittest.constraints.BooleanConstraint


Related Examples



  • “Create Custom Constraint” on page 33-150


See Also
Free download pdf