classdef testCrystal < TestCase
    methods
        %% Setup functions
        function self = testCrystal(name)
            self = self@TestCase(name);
        end
        
        %% obtainCrystal with database
        % testing database handling
        function testCrystalDatabaseInit(self)
            % this should display some text:
            outString = evalc('obtainCrystal');
            outStringTwo = evalc('obtainCrystal(''init'')');
            assertTrue(strcmp(outString, outStringTwo), ...
                'euqal response expected for obtainCrystal and obtainCrystal(''init'')');
            assertFalse(strcmp('ans', outString), ...
                'obtainCrystal should list names from the crystal database');
         
        end
        
        % testing all existent cases
        function testCrystalDatabase(self)
            cdefList = obtainCrystal('init');
            
            % we only test if some definition is generated
            for iCase = 1:length(cdefList)
                cdef = obtainCrystal(cdefList(iCase).name, []);
            end       
        end
        
        %% viewCrystal
        % basics and vector-input
        function testCrystalViewVector(self)
            cdef = obtainCrystal('cuboid', []);
            % full vector
            viewCrystal(cdef, ones(6,1));
            close all
            % row vector
            viewCrystal(cdef, ones(1,6));
            close all
            % hC-vector
            viewCrystal(cdef, ones(1,3));
            close all
            % wrong vector
            assertExceptionThrown(@()(viewCrystal(cdef, ones(1,4))), ...
                'elk:crystal:wrongInput');
        end
        
        % options for viewCrystal
        function testCrystalViewOption(self)
            cdef = obtainCrystal('cuboid');
            % ensure database works (next call must be from precalculated
            % data:
            cdef = obtainCrystal('cuboid');
            % hC-vector
            viewCrystal(cdef, ones(1,3), ...
                'colormap', [1 0 0;0 1 0; 0 0 1], ...
                'option', struct('shade', 0.2), ...
                'zerotol', 1e-7);
            close all
            % colorbar
            viewCrystal(cdef, ones(1,3), ...
                'colorbar', 0);
            close all
        end
        
    end
end