
function test_suite = testEMLGenerator
initTestSuite;
end


function testparse_inputs
    input_string = 'x';
    ri = EMLGenerator.parse_inputs(input_string);
    
    assertEqual(char(ri{1}(1)),'x');
    input_string = 'x:boolean';
    ri = EMLGenerator.parse_inputs(input_string);
    assertEqual(char(ri{1}(1)),'x');
    assertEqual(char(ri{1}(2)),'boolean');
    input_string = 'a:boolean,c,d:{x:real|x<2}';
        ri = EMLGenerator.parse_inputs(input_string);
        assertEqual(char(ri{1}(1)),'a');
        assertEqual(char(ri{1}(2)),'boolean');
        assertEqual(char(ri{2}(1)),'c');
        assertEqual(char(ri{3}(1)),'d');
        assertEqual(char(ri{3}(2)),'{x:real|x<2}');
    
        input_string = 'rewq$32:fwer';
        ri = EMLGenerator.parse_inputs(input_string);
        assertEqual(char(ri{1}(2)),'error');

         input_string = ',,,,';
        ri = EMLGenerator.parse_inputs(input_string);
        assertEqual(char(ri{1}(2)),'error');

end

function testpreamble
    d = Data;
    d.init;
    d.function_name  = 'test';
    d.function_inputs = 'x';
    d.Grid1.cells(1).cond_text = 'x>1';
    d.Grid1.new_Cell;
    d.Grid1.cells(2).cond_text = 'x<=1';
    d.Grid0.Cells(1).result_text = '1';
    d.Grid0.Cells(2).result_text = '2';
    E = EMLGenerator(d);
    pre = E.generate_preamble;
    assertEqual(pre,sprintf('function output = test(x)\n%%%%#eml\noutput=(1);\n'));
    
    d.function_name = 'test2';
    pre = E.generate_preamble;
    assertEqual(pre,sprintf('function output = test2(x)\n%%%%#eml\noutput=(1);\n'));
    
     d.function_name = 'test3';
    E.set_datatype('logical');
        pre = E.generate_preamble;

    assertEqual(pre,sprintf('function output = test3(x)\n%%%%#eml\noutput=logical(1);\n'));
    
    
end

function testcode_gen
    d = Data;
    d.init;
    d.function_name  = 'test';
    d.function_inputs = 'x';
    d.Grid1.cells(1).cond_text = 'x>1';
    d.Grid1.new_Cell;
    d.Grid1.cells(2).cond_text = 'x<=1';
    d.Grid0.Cells(1).result_text = '1';
    d.Grid0.Cells(2).result_text = '2';
    E = EMLGenerator(d);
    code = E.generate_eml_code;
    assertEqual(code,sprintf('function output = test(x)\n%%%%#eml\noutput=(1);\nif(x>1)\n  output = (1);\nelseif(x<=1)\n  output = (2);\nend\n'));
    
    
    d.Grid1.cells(1).cond_text = 'x+1<2';
    d.Grid1.cells(2).cond_text = 'x-1>6';
        code = E.generate_eml_code;
    assertEqual(code,sprintf('function output = test(x)\n%%%%#eml\noutput=(1);\nif(x+1<2)\n  output = (1);\nelseif(x-1>6)\n  output = (2);\nend\n'));

    
    d.Grid2.new_Cell;
    d.Grid2.cells(1).cond_text = 'x+1<2';
    d.Grid2.cells(2).cond_text = 'x-1>6';
    d.Grid1.cells(1).cond_text = 'y<1';
    d.Grid1.cells(2).cond_text = 'y>=1';
    d.Grid0.Cells(3).result_text = '3';
    d.Grid0.Cells(4).result_text = '4';
    code = E.generate_eml_code;
    assertEqual(code,sprintf('function output = test(x)\n%%%%#eml\noutput=(1);\nif(x+1<2)\n  if(y<1)\n    output = (1);\n  elseif(y>=1)\n    output = (2);\n  end\nelseif(x-1>6)\n  if(y<1)\n    output = (3);\n  elseif(y>=1)\n    output = (4);\n  end\nend\n'));


%     d.function_name = 'test2';
%     pre = E.generate_preamble;
%     assertEqual(pre,sprintf('function output = test2(x)\n%%%%#eml\noutput=(1);\n'));
%     
%      d.function_name = 'test3';
%     E.set_datatype('logical');
%         pre = E.generate_preamble;
% 
%     assertEqual(pre,sprintf('function output = test3(x)\n%%%%#eml\noutput=logical(1);\n'));
    
    
end

