function [passed,results] = run_gdat_tests(test_case)
% test runner for gdat

% F. Felici, EPFL federico.felici@epfl.ch

if nargin==0 || isempty(test_case)
  test_case = 'basic'; % default
end

%% populate suite
% add path with tests
addpath(genpath(fullfile(fileparts(mfilename('fullpath')),'tests')));
addpath(genpath(fullfile(fileparts(mfilename('fullpath')),'TCV_IMAS')));

suite_all = [matlab.unittest.TestSuite.fromClass(?test_requestnames_TCV),...
  matlab.unittest.TestSuite.fromClass(?test_requestnames_AUG),...
  matlab.unittest.TestSuite.fromClass(?test_tcv_get_ids)];

switch test_case
  case 'all'
    suite = suite_all; % run all
  case 'basic'
    import matlab.unittest.selectors.HasParameter;
    import matlab.unittest.selectors.HasName;
    import matlab.unittest.selectors.HasTag;
    import matlab.unittest.constraints.ContainsSubstring;
    
    s1 = HasName(ContainsSubstring('TCV')) & ...
      (HasParameter('Value','ip') | HasParameter('Value','q_rho'));    
    suite = suite_all.selectIf(s1);
  case 'IMAS'
    s2 = HasTag('IMAS');
    suite = suite_all.selectIf(s2);
  otherwise
    error('not yet implemented')
end

%% run it
fprintf('Start test case: %s\n%s\n\n',test_case,datestr(now));
results = run(suite);
disp(table(results));
fprintf('\nTotal test duration: %5.2fs\n',sum(table(results).Duration))

%% display results
if all([results.Passed])
  fprintf('\nPassed all tests\n')
  passed = true;
else
  fprintf('\nSome tests Failed or Incomplete\n')
  if any([results.Incomplete])
    fprintf('\nIncomplete:\n')
    disp(table(results([results.Incomplete])))
  end
  if any([results.Failed])
    fprintf('\nFailed:\n')
    disp(table(results([results.Failed])));
  end
  passed = false;
end

end
