getNegativeDiagnosticFor

Class: matlab.unittest.constraints.BooleanConstraint
Package: matlab.unittest.constraints

Produce negated diagnostic for value

Syntax

diag = getNegativeDiagnosticFor(constObj, actVal)

Description

diag = getNegativeDiagnosticFor(constObj, actVal) produces a negated diagnostic for a value. The getNegativeDiagnosticFor method analyzes the provided value, actVal, against the constraint, constObj, and produces a matlab.unittest.diagnostics.Diagnostic object, diag, which corresponds to the negation of the constraint, constObj. This method is a protected method.

The diagnostics that this method produces are expressed in the negative sense of the constraint. For example, a hypothetical IsTasty constraint, when negated, should express that the actual value was "tasty", when it should not have been, and it should describe the details on why it was found to be tasty.

Like the getDiagnosticFor method of Constraint, the getNegativeDiagnosticFor is only called upon failures, and thus can afford a more detailed analysis than the satisfiedBy method.

Input Arguments

constObj

BooleanConstraint instance

actVal

Value for comparison

Examples

expand all

function diag = getNegativeDiagnosticFor(constraint, actual)
% getNegativeDiagnosticFor - produce a diagnostic when the constraint is
% incorrectly met
%
%   This method is called by the testing framework when the constraint has
%   been met but should not have been met because it was negated in a
%   boolean expression. It should produce a Diagnostic result that
%   describes the failure in the correct terms which express the
%   requirement that the constraint actually should not have been met.

import matlab.unittest.diagnostics.StringDiagnostic

if constraint.satisfiedBy(actual)
    % Create the negative diagnostic. This will show information such as the
    % constraint class name and display the raw actual and expected values.
    % Using the DiagnosticSense.NegativeDiagnostic enumeration also
    % produces language more appropriate for the negated case.
    diag = StringDiagnostic(sprintf(...
        ['Negated HasSameSizeAs failed.\nSize [%s] of ' ...
        'Actual Value and Expected Value were the same ' ...
        'but should not have been.', int2str(size(actual))));
else
    % Produce a passing diagnostic, with language appropriate for 
    % the negated case.
    diag = StringDiagnostic('Negated HasSameSizeAs passed.');
end % if

end % function
Was this topic helpful?