Main Content

matlab.unittest.constraints.IsScalar class

Package: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.BooleanConstraint

Constraint specifying scalar value

Construction

IsScalar provides a constraint that specifies a scalar value. The constraint is satisfied if the actual value is a scalar.

Copy Semantics

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

Examples

collapse all

Create a test case for interactive testing.

import matlab.unittest.TestCase
import matlab.unittest.constraints.IsScalar

testCase = TestCase.forInteractiveUse;

Verify that a value of zero satisfies the IsScalar constraint.

testCase.verifyThat(0,IsScalar)
Interactive verification passed.

Assert that a single object is scalar.

testCase.assertThat(timeseries(1),IsScalar)
Interactive verification passed.

Verify that a vector is not scalar.

testCase.verifyThat([2 3],IsScalar)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsScalar failed.
--> The value must be a scalar.
--> The value has a size of [1  2].

Actual Value:
         2     3

Assert that an empty structure does not satisfy the IsScalar constraint.

testCase.assertThat(struct([]),IsScalar)
Interactive assertion failed.

---------------------
Framework Diagnostic:
---------------------
IsScalar failed.
--> The value must be a scalar.
--> The value has a size of [0  0].

Actual Value:
    0x0 struct array with no fields.
Assertion failed.
Introduced in R2014b