matlab.unittest.qualifications.Verifiable.verifyLessThan - Verify value is less than specified value - MATLAB (original) (raw)
Class: matlab.unittest.qualifications.Verifiable
Namespace: matlab.unittest.qualifications
Verify value is less than specified value
Syntax
Description
verifyLessThan([testCase](#bt00qoh-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5Ff6cc0aed-a117-43d6-b609-9e0f81bfc10a),[ceiling](#mw%5F05f17499-08f6-4997-9d3b-18f8b8e2e9c3))
verifies that all elements of actual
are less than all elements ofceiling
.
verifyLessThan([testCase](#bt00qoh-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5Ff6cc0aed-a117-43d6-b609-9e0f81bfc10a),[ceiling](#mw%5F05f17499-08f6-4997-9d3b-18f8b8e2e9c3),[diagnostic](#mw%5Fb3adea15-7528-469a-98d2-ea7a79efb376))
also associates the diagnostic information in diagnostic
with the qualification.
Input Arguments
Test case, specified as a matlab.unittest.qualifications.Verifiable
object. Because the matlab.unittest.TestCase class subclasses matlab.unittest.qualifications.Verifiable
and inherits its methods, testCase
is typically amatlab.unittest.TestCase
object.
Diagnostic information to display when the qualification passes or fails, specified as a string array, character array, function handle, or array of matlab.automation.diagnostics.Diagnostic objects.
Depending on the test runner configuration, the testing framework can display diagnostics when the qualification passes or fails. By default, the framework displays diagnostics only when the qualification fails. You can override the default behavior by customizing the test runner. For example, use a DiagnosticsOutputPlugin instance to display both failing and passing event diagnostics.
Example: "My Custom Diagnostic"
Example: @dir
Examples
Create a test case for interactive testing.
testCase = matlab.unittest.TestCase.forInteractiveUse;
Verify that 2
is less than 3
.
verifyLessThan(testCase,2,3)
Test if 9
is less than 5
. The test fails.
verifyLessThan(testCase,9,5)
Verification failed. --------------------- Framework Diagnostic: --------------------- verifyLessThan failed. --> The value must be less than the maximum value.
Actual Value:
9
Maximum Value (Exclusive):
5
------------------
Stack Information:
------------------
In C:\work\CompareTwoNumbersExample.m (CompareTwoNumbersExample) at 16
Create a test case for interactive testing.
testCase = matlab.unittest.TestCase.forInteractiveUse;
Test if each element of the vector [5 6 7]
is less than the ceiling value 9
.
verifyLessThan(testCase,[5 6 7],9)
Test if 2
is less than each element of the ceiling vector [5 6 7]
.
verifyLessThan(testCase,2,[5 6 7])
Test if each element of the matrix [1 2 3; 4 5 6]
is less than the ceiling value 4
. The test fails.
verifyLessThan(testCase,[1 2 3; 4 5 6],4, ... "All elements must be less than the ceiling value.")
Verification failed. ---------------- Test Diagnostic: ---------------- All elements must be less than the ceiling value. --------------------- Framework Diagnostic: --------------------- verifyLessThan failed. --> Each element must be less than the maximum value.
Failing Indices:
2 4 6
Actual Value:
1 2 3
4 5 6
Maximum Value (Exclusive):
4
------------------
Stack Information:
------------------
In C:\work\CompareArrayToScalarExample.m (CompareArrayToScalarExample) at 22
Create a test case for interactive testing.
testCase = matlab.unittest.TestCase.forInteractiveUse;
Test if each element of the array [5 -3 2]
is less than each corresponding element of the ceiling array [7 -1 8]
.
verifyLessThan(testCase,[5 -3 2],[7 -1 8])
Compare an array to itself. The test fails.
verifyLessThan(testCase,eye(2),eye(2))
Verification failed. --------------------- Framework Diagnostic: --------------------- verifyLessThan failed. --> Each element must be less than each corresponding element of the maximum value array.
Failing Indices:
1 2 3 4
Actual Value:
1 0
0 1
Maximum Value (Exclusive):
1 0
0 1
------------------
Stack Information:
------------------
In C:\work\CompareArraysExample.m (CompareArraysExample) at 17
Tips
verifyLessThan
is a convenience method. For example,verifyLessThan(testCase,actual,ceiling)
is functionally equivalent to the following code.
import matlab.unittest.constraints.IsLessThan
testCase.verifyThat(actual,IsLessThan(ceiling))- Use verification qualifications to produce and record failures without throwing an exception. Because verifications do not throw exceptions, all test content runs to completion even when verification failures occur. Typically, verifications are the primary qualification for a unit test because they typically do not require an early exit from the test. Use other qualification types to test for violation of preconditions or incorrect test setup:
- Use assumption qualifications to ensure that the test environment meets preconditions that otherwise do not result in a test failure. Assumption failures result in filtered tests, and the testing framework marks the tests as
Incomplete
. For more information, see matlab.unittest.qualifications.Assumable. - Use assertion qualifications when the failure condition invalidates the remainder of the current test content but does not prevent proper execution of subsequent tests. A failure at the assertion point renders the current test as
Failed
andIncomplete
. For more information, see matlab.unittest.qualifications.Assertable. - Use fatal assertion qualifications to abort the test session upon failure. These qualifications are useful when the failure is so fundamental that continuing testing does not make sense. Fatal assertion qualifications are also useful when fixture teardown does not restore the environment state correctly, and aborting testing and starting a fresh session is preferable. For more information, see matlab.unittest.qualifications.FatalAssertable.
- Use assumption qualifications to ensure that the test environment meets preconditions that otherwise do not result in a test failure. Assumption failures result in filtered tests, and the testing framework marks the tests as
Version History
Introduced in R2013a