
%

%   Copyright 2012 The MathWorks, Inc.

classdef TestRunnerAverage < coder.rtiostreamtest.TestRunner
    %TESTRUNNERAVERAGE runs a set of TESTs and averages their results
    %   Similar to a TestRunner; it runs a supplied list of tests in order
    %   but it also takes their results and calculates the average.
    %   If a result is < 0 (inconclusive) then TestRunnerAverage also
    %   returns < 0
    
    methods
        
        function this = TestRunnerAverage(tests, name)
            if nargin == 1, name = 'TestRunnerAverage'; end;
            this = this@coder.rtiostreamtest.TestRunner(tests, name);
        end
        
        function result = runTest(this, connection, parameters)
            
            inconclusive = false;
            
            % Initialize the holder array
            results = zeros(1, numel(this.tests));
            
            % Perform the test
            for i = 1:numel(this.tests)
                results(i) = this.tests{i}.runTest(connection, parameters);
                if results(i) < 0, inconclusive = true; end;
            end
            
            % Get the average
            if ~inconclusive
                result = mean(results);
            else
                result = -1;
            end
        end
    end
    
end

