classdef testMptBugs < TestCase
    methods
        function self = testMptBugs(name)
            self = self@TestCase(name);
        end
        
        function testVolumeOnSphere(self)
            % extreme points of a sphere approximation
            % (code from obtainSphere, Rev 154)
            n = 15;
            
            phi = 0:(pi/n):(pi-pi/n/2);
            theta = 0:(pi/n):(2*pi-pi/n/2);
            
            phi = ones(2*n,1)*phi;
            theta = theta'*ones(1,n);
            
            X = sin(theta).*cos(phi);
            Y = sin(theta).*sin(phi);
            Z = cos(theta);
            
            CH(:,1) = X(:);
            CH(:,2) = Y(:);
            CH(:,3) = Z(:);
            
            PT = polytope(CH);
            extremePT = extreme(PT);
            % check points being on unit sphere:
            assertElementsAlmostEqual(...
                extremePT(:,1).^2+extremePT(:,2).^2+extremePT(:,3).^2,...
                extremePT(:,1)*0+1, 'absolute', 1e-10, ...
                'Extreme points should be on the unit sphere')
            % check volumes
            [K, volumeConvHull] = convhulln(CH);
            volumeMpt = volume(PT);
%             assertElementsAlmostEqual(volumeConvHull, 4/3*pi, ...
%                 'absolute', 1e-15, 'Convex hull error')
            assertElementsAlmostEqual(volumeMpt, 4/3*pi, ...
                'absolute', 1e-1, ...
                ['Mpt error with the volume much larger than possible. ' ...
                 'For reference volume from convexhulln:' ...
                 num2str(volumeConvHull)])
        end

    end
end