
%

%   Copyright 2012 The MathWorks, Inc.

classdef AverageTest < coder.rtiostreamtest.TestDecorator
    %AVERAGETEST Does averaging of the enclosed test
    %   The enclosed test must have exactly one output for its runTest
    %   method. A certain number of calls to the runTest method of the
    %   enclosed class averaged over.
    %
    %   Parameters:
    %
    %       repeats -
    %           an integer number of times to repeat the test in order to
    %           make the averaging.
    
    % Available parameters defined here
    properties (Constant)
        param_repeats   = 'repeats';
        
        default_repeats = 1; % Repeat just once by default
    end
    
    methods
        
        function this = AverageTest(test)
            this = this@coder.rtiostreamtest.TestDecorator(test);
        end
        
        function result = runTest(this, connection, parameters)
            % Conducts the averaging
            
            % Get the number of times the averaging needs to be done
            times = coder.rtiostreamtest.Test.getSetting(parameters, this.param_repeats, this.default_repeats);
            
            % Initialize the array required for the averaging
            arr = zeros(1, times);
            
            % Call the enclosed test the required number of times
            for i = 1 : times
                arr(i) = this.test.runTest(connection, parameters);
            end
            
            % Calculate and return the mean
            result = mean(arr);
        end
        
    end
    
end

