classdef testPolytopeCore < TestCase
    methods
        function self = testPolytopeCore(name)
            self = self@TestCase(name);
        end
        
        %% polytope dimensions
        function testObtainSimple3d(self)
            Vrep = obtainVrep('cube');
            assertEqual(size(Vrep.V, 2), 3, 'dimension should be 3');
        end
        
        function testObtainSimple2d(self)
            Vrep = obtainVrep('polygon', 5, 2);
            assertEqual(size(Vrep.V, 2), 2, 'dimension should be 2');
        end
        
        function testObtainSimple1d(self)
            Vrep = obtainVrep('line', [], 1);
            assertEqual(size(Vrep.V, 2), 1, 'dimension should be 1');
        end
        
        %% parameter polytopes
        function testObtainWithParameter3d(self)
            Vrep = obtainVrep('bipyramid', 6);
            assertEqual(size(Vrep.V, 2), 3, 'dimension should be 3');
        end
        
        function testObtainSphere(self)
            Vrep = obtainVrep('sphere', 10);
            assertEqual(size(Vrep.V, 2), 3, 'dimension should be 3');
            
            assertElementsAlmostEqual(...
                Vrep.V(:,1).^2+Vrep.V(:,2).^2+Vrep.V(:,3).^2,...
                Vrep.V(:,1)*0+1, 'absolute', 1e-10, ...
                'Extreme points should be on the unit sphere')
            
            [K, V] = convhulln(Vrep.V);
            assertElementsAlmostEqual(V, 4/3*pi, 'absolute', 1.7e-1, ...
                'Quality: accuracy of volume is bad.')
            
        end
        
        function testObtainCircle3d(self)
            Vrep = obtainVrep('circle', 10);
            assertEqual(size(Vrep.V, 2), 3, 'dimension should be 3');
        end
        
        function testObtainCircle2d(self)
            Vrep = obtainVrep('circle', 100, 2);
            assertEqual(size(Vrep.V, 2), 2, 'dimension should be 3');
            [K, V] = convhulln(Vrep.V);
            assertElementsAlmostEqual(V, pi, 'absolute', 3e-3, ...
                'Quality: accuracy of volume is bad.')
        end
        
        function testObtainLine3d(self)
            Vrep = obtainVrep('line', []);
            assertEqual(size(Vrep.V, 2), 3, 'dimension should be 3');
        end
    
    end
end