Eötvös Quantum Utilities  v4.8.128
Providing the Horsepowers in the Quantum Realm
automatic_test.m
Go to the documentation of this file.
1 % Automatic test procedure - based on EQuUs v4.8
2 % Copyright (C) 2015 Peter Rakyta, Ph.D.
3 %
4 % This program is free software: you can redistribute it and/or modify
5 % it under the terms of the GNU General Public License as published by
6 % the Free Software Foundation, either version 3 of the License, or
7 % (at your option) any later version.
8 %
9 % This program is distributed in the hope that it will be useful,
10 % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 % GNU General Public License for more details.
13 %
14 % You should have received a copy of the GNU General Public License
15 % along with this program. If not, see http://www.gnu.org/licenses/.
16 %
17 %> @file automatic_test.m
18 %> @brief Launches the automatic test procedure. First, source code functionalities are checked by processing the unit tests in directory 'UnitTests' and then larger computational tasks are performed via examples in directory 'Examples'
19 %> @Available
20 %> EQuUs v4.9 or later
21 %
22 %> @brief Launches the automatic test procedure. First, source code functionalities are checked by processing the unit tests in directory 'UnitTests' and then larger computational tasks are performed via examples in directory 'Examples'
23 function automatic_test()
24 
25 filename = mfilename('fullpath');
26 root = fileparts( filename );
27 cd(root)
28 
29 
30 
31 %% performing larger computational tasks
32 
33 % Examples to run
34 fncnames = { 'magnetic_ribbon', ...
35  'MinimalConductivity', ...
36  'Graphene_Conductivity', ...
37  'magnetic_barrier', ...
38  'Differential_conductance', ...
39  'Graphene_QAD_eig', ...
40  'Graphene_antidot_transport', ...
41  'JosephsonCurrent', ...
42  'SpectralDensity', ...
43  'SSH_transport', ...
44  'SSH_Josephson' ...
45  };
46 
47 Dirs = { 'magnetic_ribbon', ... 1
48  'Graphene_Minimal_Conductivity', ... 2
49  'Graphene_Conductivity', ... 3
50  'magnetic_barrier_0B0', ... 4
51  'Differential_conductance', ... 5
52  'Graphene_antidot_eigenstate', ... 6
53  'Graphene_antidot_transport', ... 7
54  'SNS_Josephson', ... 8
55  'SpectralDensity', ... 9
56  'SSH_transport', ... 10
57  'SSH_Josephson' ... 11
58  };
59 
60 % These tests are skipped during the test procedure
61 skip_tests = [10 11];
62 
63 % the filename of the output to be exported in
64 output_file = 'automatic_test_results.txt';
65 
66 
67 
68 % removing previous debug files
69 delete( [root, filesep, 'Examples', filesep, '*', filesep, 'debug.txt'] );
70 
71 test_results = false(size(fncnames));
72 
73 for jdx = 1:length(fncnames)
74 
75  if ~isempty( find(jdx == skip_tests, 1) )
76  continue
77  end
78 
79  test_results(jdx) = runTest( fncnames{jdx}, Dirs{jdx});
80 
81  if test_results(jdx)
82  fid = fopen(output_file, 'a');
83  fprintf(fid, ['Test ', fncnames{jdx}, ' finished succesfully. Check the results.\n']);
84  fclose(fid);
85  else
86  fid = fopen(output_file, 'a');
87  fprintf(fid, ['Test ', fncnames{jdx}, ' failed due to coding error.\n']);
88  fclose(fid);
89  end
90 end
91 
92 
93 
94 
95 if norm( true(size(test_results)) - test_results ) <= 1e-6
96  disp('*************************');
97  disp('*************************');
98  disp('All tests passed.')
99  disp('*************************');
100 else
101  for jdx = 1:length(fncnames)
102  if test_results( jdx )
103  continue
104  end
105  failed_fncname = fncnames{ jdx };
106  failed_Dir = Dirs{jdx};
107  disp(['Test ', fullfile(root, 'Examples', failed_Dir, failed_fncname), ' failed.']);
108  end
109 end
110 
111 
112 
113 
114 %% runTest
115 %> @brief Runs the test for a specific example
116 %> @param fncname The name of the exmaple to be started.
117 %> @param directory The absolut path to the directory containing the test case.
118  function ret = runTest( fncname, directory)
119 
120  disp( '**************************************' )
121  disp( ['starting test: ', fncname] )
122  disp( '**************************************' )
123  try
124  directory = fullfile( root, 'Examples', directory);
125  filenum = getFilenum( directory );
126  cd(directory)
127  feval( fncname, filenum );
128  cd(root)
129  ret = true;
130  catch err
131  ret = false;
132  return;
133  end
134 
135  end
136 
137 
138 %% getFilenum
139 %> @brief Determines the up-comming 'filenum' input.
140 %> @param directory The absolut path to the directory containing the test case.
141 %> @return Returns with the next filenum value to run the test case.
142  function ret = getFilenum( directory )
143  ret = 1;
144 
145  numerics = {'1' '2' '3' '4' '5' '6' '7' '8' '9' '0'};
146 
147  start_idx = [];
148  end_idx = [];
149 
150  try
151  list = dir( fullfile( directory, 'results', '*.mat') );
152  catch err
153  ret = 1;
154  return
155  end
156 
157  if isempty( list )
158  ret = 1;
159  return
160  end
161 
162 
163  for kdx = 1:length(list)
164  filename_tmp = list(kdx).name;
165  for idx = 1:length(filename_tmp)
166  character = filename_tmp(idx);
167  comp = find(strcmp( character, numerics ));
168 
169  if norm(comp) > 0
170  if isempty( start_idx )
171  start_idx = idx;
172  end
173  else
174  if isempty( end_idx ) && ~isempty( start_idx )
175  end_idx = idx;
176  end
177  end
178 
179 
180  if ~isempty( start_idx ) && ~isempty(end_idx )
181  number_tmp = str2double( filename_tmp(start_idx:end_idx-1) );
182  if ret < number_tmp
183  ret = number_tmp;
184  end
185  start_idx = [];
186  end_idx = [];
187  end
188 
189 
190  end
191  end
192 
193  ret = ret+1;
194 
195 
196 
197  end
198 
199 
200 end
function test(arg1, arg2)
Brief description of the function.
Fortran compatible complex type.
function runTest(fncname, directory)
Runs the test for a specific example.
Structure param contains data structures describing the physical parameters of the scattering center ...
Definition: structures.m:45
function getFilenum(directory)
Determines the up-comming &#39;filenum&#39; input.
function automatic_test()
Launches the automatic test procedure. First, source code functionalities are checked by processing t...