Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

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

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 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.
    --> Class check failed.
        --> Classes do not match.
            
            Actual Class:
                double
            Expected Class:
                logical

Actual double:
         1
Expected logical:
         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.

Introduced in R2013a

Was this topic helpful?