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.StringComparator class

Package: matlab.unittest.constraints

Comparator for two strings or character arrays

Construction

StringComparator creates a comparator for two strings or character arrays. The comparator is satisfied if the two values are equal.

StringComparator(Name,Value) creates a comparator with additional options specified by one or more Name,Value pair arguments.

Input Arguments

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

'IgnoringCase'

Indicator if the comparator is insensitive to case, specified as false or true (logical 0 or 1). When it is false, the comparator is sensitive to case.

Default: false

'IgnoringWhitespace'

Indicator if the comparator is insensitive to whitespace characters, specified as false or true (logical 0 or 1). When it is false, the comparator is sensitive to whitespace characters. Whitespace characters consist of space, form feed, new line, carriage return, horizontal tab, and vertical tab.

Default: false

Properties

IgnoreCase

Indicator if the comparator is insensitive to case, specified in the name-value pair argument, 'IgnoringCase'

IgnoreWhitespace

Indicator if the comparator is insensitive to whitespace characters, specified in the name-value pair argument, 'IgnoringWhitespace'

Copy Semantics

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

Examples

expand all

Create a test case for interactive testing.

import matlab.unittest.TestCase
import matlab.unittest.constraints.StringComparator
import matlab.unittest.constraints.IsEqualTo

testCase = TestCase.forInteractiveUse;

Verify that the actual and expected character vectors are equal using a string comparator.

expected = 'coffee';
actual = 'coffee';
testCase.verifyThat(actual,IsEqualTo(expected, ...
    'Using', StringComparator))
Interactive verification passed.

Change the actual character vector and repeat the comparison.

expected = 'coF Fee';
testCase.verifyThat(actual,IsEqualTo(expected, ...
    'Using', StringComparator))
Interactive verification failed.

---------------------
Framework Diagnostic:
---------------------
IsEqualTo failed.
--> StringComparator failed.
    --> The character arrays are not equal.
    
    Actual char:
        coffee
    Expected char:
        coF Fee

For the test to pass, construct a comparator that ignores case and whitespace characters.

testCase.verifyThat(actual,IsEqualTo(expected, ...
    'Using', StringComparator('IgnoringCase', true, ...
    'IgnoringWhitespace', true)))
Interactive verification passed.

Introduced in R2013a

Was this topic helpful?