function r = plus(p,q)
%CVDATA/PLUS   Implement P+Q, data union.
%
% When a test metric exists in only one of the arguments it will be copied 
% from that argument into the result. When the same metric exists in both 
% arguments the following union rules apply:
% 
% DECISION The path counts are the sum of the counts in P and Q and the 
% aggregate results are calculated from these sums.
% 
% CONDITION The condition evaluation counts are the sum of the counts in P 
% and Q and the aggregate results are calculated from these sums.

%   Copyright 1990-2019 The MathWorks, Inc.

p = cvdata(p);
q = cvdata(q);

% Perform consistency checking
p.checkDataCompatibility(q);

ati = cvdata.joinAggregatedTestInfo(p, q);
opFcn = @(x)(sum(x,2));
[out_metrics, traceStruct] = perform_operation(p,q,opFcn,'+', ati);
[ati, traceStruct] = cvdata.removeDuplicateTestTraces(ati, traceStruct);


r = cvdata;
r.createDerivedData(p, q, out_metrics, traceStruct);
r.aggregatedTestInfo = ati;

r.sfcnCovData = SlCov.results.CodeCovDataGroup.performOp(p.sfcnCovData, q.sfcnCovData, '+');
r.codeCovData = SlCov.results.CodeCovData.performOp(p.codeCovData, q.codeCovData, '+');
