classdef testDistributionCore < TestCase
    methods
        %% Setup functions
        function self = testDistributionCore(name)
            self = self@TestCase(name);
        end
           
        %% obtainDistributionContinuous
%         function testDecCube(self)
%         end
        
        %% obtainDistributionDiscrete (ray)
        function testRayDiscrete(self)
        % 1D ray
        rng(1)
        disD = obtainDistributionDiscrete('ray', ...
            'nSample', 1e4, 'ray', 2, 'radius', 1);
        volumeCalc = 1/disD.probabilityVector(1);
        volumeDist = max(disD.positionMatrix) - min(disD.positionMatrix);
        assertTrue(volumeCalc > 0.95*volumeDist, ['mismatch of volume ' ...
            'for 1D ray distribution']);
        
        % 2D ray
        disD = obtainDistributionDiscrete('ray', ...
            'nSample', 1e5, 'ray', [50 -2]*1000, 'radius', 1);
        [K, volumeDist] = convhulln(disD.positionMatrix');
        volumeCalc = 1/disD.probabilityVector(1);
        assertTrue(volumeCalc > 0.95*volumeDist, ['mismatch of volume ' ...
            'for 2D ray distribution']);
        
        % 3D ray
        disD = obtainDistributionDiscrete('ray', ...
            'nSample', 1e6, 'ray', [1 -20 300]*1e-4, 'radius', 1);
        [K, volumeDist] = convhulln(disD.positionMatrix');
        volumeCalc = 1/disD.probabilityVector(1);
        assertTrue(volumeCalc > 0.95*volumeDist, ['mismatch of volume ' ...
            'for 3D ray distribution']);
        
        % 3D extra density check
        disD = obtainDistributionDiscrete('ray', ...
            'nSample', 1e6, 'ray', [1 0 0], 'radius', 1);
        distanceVector = sqrt(disD.positionMatrix(2,:).^2 + ...
            disD.positionMatrix(3,:).^2);
        radiusHalfPoint = 1/sqrt(2);
        filter = distanceVector < radiusHalfPoint*disD.positionMatrix(1,:);
        ratio = sum(filter) / length(filter);
        assertTrue(ratio < 0.51 & ratio > 0.49, ['3D distribution soes not ' ...
            'seem to be equally distributed']);
        radiusDense = 1/sqrt(20);
        filter = distanceVector < radiusDense*disD.positionMatrix(1,:);
        ratio = sum(filter) / length(filter);
        assertTrue(ratio < 0.051 & ratio > 0.049, ['3D distribution soes not ' ...
            'seem to be equally distributed']); 
        end
        
        
        
     
    end
end