Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.unittest.constraints.BooleanConstraint class

Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.Constraint

Interface class for boolean combinations of constraints

Description

The BooleanConstraint interface class provides an interface for boolean combinations of Constraints. Any constraint that derives from BooleanConstraint can be combined and negated using the and (&), or (|), and not (~) operators.

Classes that derive from the BooleanConstraint interface class must implement everything required by the standard Constraint interface. When a given constraint is negated, the diagnostics must be written in a different form than for a standard (non-negated) failure. Therefore, classes deriving from the BooleanConstraint class must implement a method to provide a Diagnostic object for the negated case, in addition to the non-negated case.

In exchange for meeting these requirements, all BooleanConstraint implementations inherit the appropriate MATLAB® overloads for and, or, and not so that they can be combined with other BooleanConstraint objects or negated.

Methods

getNegativeDiagnosticForProduce negated diagnostic for value

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects.

Examples

expand all

At the command prompt, create a test case for interactive testing and import several classes that subclass BooleanConstraint.

import matlab.unittest.TestCase
import matlab.unittest.constraints.HasElementCount
import matlab.unittest.constraints.HasLength
import matlab.unittest.constraints.HasInf
import matlab.unittest.constraints.HasNaN
import matlab.unittest.constraints.IsEmpty
import matlab.unittest.constraints.IsEqualTo
import matlab.unittest.constraints.IsGreaterThanOrEqualTo
import matlab.unittest.constraints.IsOfClass
import matlab.unittest.constraints.IsReal

testCase = TestCase.forInteractiveUse;

Test these passing cases.

testCase.verifyThat(3, IsReal & IsGreaterThanOrEqualTo(3))
testCase.verifyThat([1 2 3; 4 5 6], HasLength(3) & HasElementCount(6))
testCase.verifyThat([3 NaN 5], HasNaN | HasInf)
testCase.verifyThat(3, ~IsEqualTo(4))
testCase.verifyThat('Some char', IsOfClass(?char) & ~IsEmpty)
Was this topic helpful?