matlab.unittest.constraints.LogicalComparator class

Package: matlab.unittest.constraints

Comparator for two logical values

Construction

LogicalComparator creates a comparator for two logical values. The comparator is satisfied if the actual and expected values have the same sparsity and the logical values are equivalent.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.

Examples

expand all

Compare Logical Values

Create a test case for interactive testing.

import matlab.unittest.TestCase
import matlab.unittest.constraints.LogicalComparator
import matlab.unittest.constraints.IsEqualTo

testCase = TestCase.forInteractiveUse;

Test that the value of true.

testCase.assertThat(true, IsEqualTo(true, ...
    'Using', LogicalComparator))
Interactive assertion passed.

Test an array of true values.

testCase.assertThat([true true true], IsEqualTo(true, ...
    'Using', LogicalComparator))
Interactive assertion failed.

---------------------
Framework Diagnostic:
---------------------
IsEqualTo failed.
--> LogicalComparator failed.
    --> The logical values are not equal

Actual Logical Value:
         1     1     1
Expected Logical Value:
         1
Assertion failed.

The actual value must be a scalar logical to satisfy the constraint.

Compare the value of 1 to true.

testCase.verifyThat(1, IsEqualTo(true, 'Using', LogicalComparator))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsEqualTo failed.
--> LogicalComparator failed.
    --> The logical values are not equal

Actual Logical Value:
         1
Expected Logical Value:
         1

Compare the value of false to true.

testCase.assertThat(false, IsEqualTo(true, 'Using', LogicalComparator))
Interactive assertion failed.

---------------------
Framework Diagnostic:
---------------------
IsEqualTo failed.
--> LogicalComparator failed.
    --> The logical values are not equal

Actual Logical Value:
         0
Expected Logical Value:
         1
Assertion failed.
Was this topic helpful?