addConditionsFrom

Class: matlab.unittest.diagnostics.ConstraintDiagnostic
Package: matlab.unittest.diagnostics

Add condition from another ConstraintDiagnostic to condition list

Syntax

addConditionsFrom(constDiag, otherConstDiag)

Description

addConditionsFrom(constDiag, otherConstDiag) adds the conditions from the ConstraintDiagnostic instance, constDiag, to the condition list in the Diagnostic instance, diag. This is useful when a constraints composes another constraint, and needs to use the conditions produced in the diagnostics of the composed constraint.

Input Arguments

constDiag

Diagnostic to add conditions to, specified as a matlab.unittest.diagnostics.ConstraintDiagnostic instance

otherConstDiag

Diagnostic to add conditions from, specified as a matlab.unittest.diagnostics.ConstraintDiagnostic instance

Examples

expand all

% This demonstrates a constraint that composes another constraint
% and uses the addConditionsFrom method to utilize the conditions
% from the composed ConstraintDiagnostic.
classdef IsDouble < matlab.unittest.constraints.Constraint
    
    properties(Constant, GetAccess=private)
        DoubConst = matlab.unittest.constraints.IsInstanceOf(?double);
    end
    
    methods
        function tf = satisfiedBy(constraint, actual)
            tf = constraint.DoubConst.satisfiedBy(actual);
        end
        function diag = getDiagnosticFor(constraint, actual)
            diag = ConstraintDiagnostic;
            
            % Now add conditions from the IsInstanceOf
            % Diagnostic
            otherDiag = constraint.DoubConst.getDiagnosticFor(actual);
            diag.addConditionsFrom(otherDiag)
            
            % ...
        end
    end
end

See Also