matlab.unittest.qualifications.Verifiable.verifyReturnsTrue - Verify function returns true - MATLAB (original) (raw)

Class: matlab.unittest.qualifications.Verifiable
Namespace: matlab.unittest.qualifications

Verify function returns true

Syntax

Description

verifyReturnsTrue([testCase](#bt00q%5Fo-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5F3d3aef8f-bcd7-4b1c-89ef-138bca7a9f0f)) verifies that actual is a function handle that returns the logical scalar 1 (true).

example

verifyReturnsTrue([testCase](#bt00q%5Fo-1%5Fsep%5Fmw%5F8d5e73c7-bacb-46a7-a1c1-f24af91e6c03),[actual](#mw%5F3d3aef8f-bcd7-4b1c-89ef-138bca7a9f0f),[diagnostic](#mw%5Fb9ebc8c6-fef3-406e-92c0-be926e134c0d)) also associates the diagnostic information in diagnostic with the qualification.

example

Input Arguments

expand all

Test case, specified as a matlab.unittest.qualifications.Verifiable object. Because the matlab.unittest.TestCase class subclasses matlab.unittest.qualifications.Verifiable and inherits its methods, testCase is typically amatlab.unittest.TestCase object.

Value to test, specified as a value of any data type. Although you can provide a value of any data type, the test fails if actual is not a function handle.

Example: @() myFunction(1,2)

Example: @() ~strcmp('a','b')

Diagnostic information to display when the qualification passes or fails, specified as a string array, character array, function handle, or array of matlab.automation.diagnostics.Diagnostic objects.

Depending on the test runner configuration, the testing framework can display diagnostics when the qualification passes or fails. By default, the framework displays diagnostics only when the qualification fails. You can override the default behavior by customizing the test runner. For example, use a DiagnosticsOutputPlugin instance to display both failing and passing event diagnostics.

Example: "My Custom Diagnostic"

Example: @dir

Examples

expand all

Test if the actual value is a function handle that returns true.

Create a test case for interactive testing.

testCase = matlab.unittest.TestCase.forInteractiveUse;

Test the true function.

verifyReturnsTrue(testCase,@true)

Test the false function. The test fails because false does not return true.

verifyReturnsTrue(testCase,@false)

Verification failed. --------------------- Framework Diagnostic: --------------------- verifyReturnsTrue failed. --> The function handle did not evaluate to "true". --> Returned value: logical

           0

Evaluated Function:
  function_handle with value:

    @false
------------------
Stack Information:
------------------
In C:\work\TestIfFunctionReturnsTrueExample.m (TestIfFunctionReturnsTrueExample) at 19

Test if a call to isequal returns true given two equivalent numeric values.

verifyReturnsTrue(testCase,@() isequal(1,single(1)))

Verify that it is true that two different letters are not the same.

verifyReturnsTrue(testCase,@() ~strcmp('a','b'))

Test a function that returns a vector of true values. The test fails because the returned value is nonscalar.

verifyReturnsTrue(testCase,@() strcmp('a',{'a','a'}))

Verification failed. --------------------- Framework Diagnostic: --------------------- verifyReturnsTrue failed. --> The function handle did not return a scalar. The return value had a size of [1 2]. --> Returned value: 1×2 logical array

           1   1

Evaluated Function:
  function_handle with value:

    @()strcmp('a',{'a','a'})
------------------
Stack Information:
------------------
In C:\work\TestIfFunctionReturnsTrueExample.m (TestIfFunctionReturnsTrueExample) at 33

Test a function that returns a numeric value. The test fails.

verifyReturnsTrue(testCase,@ones, ... "Returned value must be a logical scalar.")

Verification failed. ---------------- Test Diagnostic: ---------------- Returned value must be a logical scalar. --------------------- Framework Diagnostic: --------------------- verifyReturnsTrue failed. --> The function handle did not return a logical value. The return value was of type "double". --> Returned value: 1

Evaluated Function:
  function_handle with value:

    @ones
------------------
Stack Information:
------------------
In C:\work\TestIfFunctionReturnsTrueExample.m (TestIfFunctionReturnsTrueExample) at 37

Tips

Version History

Introduced in R2013a