matlab.unittest.constraints.IsSparse class

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

Constraint specifying sparse array

Construction

IsSparse creates a constraint specifying a sparse array. This constraint is satisfied only when the actual value is sparse.

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.IsSparse

testCase = TestCase.forInteractiveUse;

Create an identity matrix, and test if it is sparse.

F = eye(7);
testCase.verifyThat(F, IsSparse)
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsSparse failed.
--> The value must be sparse.

Actual Value:
         1     0     0     0     0     0     0
         0     1     0     0     0     0     0
         0     0     1     0     0     0     0
         0     0     0     1     0     0     0
         0     0     0     0     1     0     0
         0     0     0     0     0     1     0
         0     0     0     0     0     0     1

The matrix, F, is a full matrix.

Convert F to a sparse matrix and retest for sparsity.

S = sparse(F);
testCase.verifyThat(S, IsSparse)
Interactive verification passed.

See Also