Eötvös Quantum Utilities  v4.9.146
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 %% code functionality checking
30 fncnames_unitTests = { 'test_Keldysh' ...
31  'test_Nambu' ...
32  'test_TMDC_Monolayer' ...
33  };
34 
35 % removing previous debug files
36 if exist( [root, filesep, 'UnitTests', filesep, 'debug.txt'], 'file' )
37  delete( [root, filesep, 'UnitTests', filesep, 'debug.txt'] );
38 end
39 
40 % change directory to the unit tests
41 cd( [root, filesep, 'UnitTests']);
42 for jdx = 1:length(fncnames_unitTests)
43  fncname = fncnames_unitTests{jdx};
44  feval( fncname );
45 end
46 
47 % change directory to EQuUs root
48 cd(root);
49 
50 
51 %% performing larger computational tasks
52 
53 % Examples to run
54 fncnames = { 'magnetic_ribbon', ...
55  'MinimalConductivity', ...
56  'Graphene_Conductivity', ...
57  'magnetic_barrier', ...
58  'Differential_conductance', ...
59  'Graphene_QAD_eig', ...
60  'Graphene_antidot_transport', ...
61  'JosephsonCurrent', ...
62  'SpectralDensity', ...
63  'Self_Consistent_Spectrum', ...
64  'Self_Consistent_Transport', ...
65  'Coulomb_Diamonds', ...
66  'TMDC_Monolayer_Spectrum', ...
67  'SSH_transport', ...
68  'SSH_Josephson' ...
69  };
70 
71 Dirs = { 'magnetic_ribbon', ... 1
72  'Graphene_Minimal_Conductivity', ... 2
73  'Graphene_Conductivity', ... 3
74  'magnetic_barrier_0B0', ... 4
75  'Differential_conductance', ... 5
76  'Graphene_antidot_eigenstate', ... 6
77  'Graphene_antidot_transport', ... 7
78  'SNS_Josephson', ... 8
79  'SpectralDensity', ... 9
80  'Self_Consistent_Spectrum', ... 10
81  'Self_Consistent_Transport', ... 11
82  'Coulomb_Diamonds', ... 12
83  'TMDC_Monolayer_Spectrum', ... 13
84  'SSH_transport', ... 14
85  'SSH_Josephson' ... 15
86  };
87 
88 % These tests are skipped during the test procedure
89 skip_tests = [14 15];
90 
91 % the filename of the output to be exported in
92 output_file = 'automatic_test_results.txt';
93 
94 
95 
96 % removing previous debug files
97 delete( [root, filesep, 'Examples', filesep, '*', filesep, 'debug.txt'] );
98 
99 test_results = false(size(fncnames));
100 
101 for jdx = 1:length(fncnames)
102 
103  if ~isempty( find(jdx == skip_tests, 1) )
104  continue
105  end
106 
107  test_results(jdx) = runTest( fncnames{jdx}, Dirs{jdx});
108 
109  if test_results(jdx)
110  fid = fopen(output_file, 'a');
111  fprintf(fid, ['Test ', fncnames{jdx}, ' finished succesfully. Check the results.\n']);
112  fclose(fid);
113  else
114  fid = fopen(output_file, 'a');
115  fprintf(fid, ['Test ', fncnames{jdx}, ' failed due to coding error.\n']);
116  fclose(fid);
117  end
118 end
119 
120 
121 
122 
123 if norm( true(size(test_results)) - test_results ) <= 1e-6
124  disp('*************************');
125  disp('*************************');
126  disp('All tests passed.')
127  disp('*************************');
128 else
129  for jdx = 1:length(fncnames)
130  if test_results( jdx )
131  continue
132  end
133  failed_fncname = fncnames{ jdx };
134  failed_Dir = Dirs{jdx};
135  disp(['Test ', fullfile(root, 'Examples', failed_Dir, failed_fncname), ' failed.']);
136  end
137 end
138 
139 
140 
141 
142 %% runTest
143 %> @brief Runs the test for a specific example
144 %> @param fncname The name of the exmaple to be started.
145 %> @param directory The absolut path to the directory containing the test case.
146  function ret = runTest( fncname, directory)
147 
148  disp( '**************************************' )
149  disp( ['starting test: ', fncname] )
150  disp( '**************************************' )
151  try
152  directory = fullfile( root, 'Examples', directory);
153  filenum = getFilenum( directory );
154  cd(directory)
155  feval( fncname, filenum );
156  cd(root)
157  ret = true;
158  catch err
159  ret = false;
160  return;
161  end
162 
163  end
164 
165 
166 %% getFilenum
167 %> @brief Determines the up-comming 'filenum' input.
168 %> @param directory The absolut path to the directory containing the test case.
169 %> @return Returns with the next filenum value to run the test case.
170  function ret = getFilenum( directory )
171  ret = 1;
172 
173  numerics = {'1' '2' '3' '4' '5' '6' '7' '8' '9' '0'};
174 
175  start_idx = [];
176  end_idx = [];
177 
178  try
179  list = dir( fullfile( directory, 'results', '*.mat') );
180  catch err
181  ret = 1;
182  return
183  end
184 
185  if isempty( list )
186  ret = 1;
187  return
188  end
189 
190 
191  for kdx = 1:length(list)
192  filename_tmp = list(kdx).name;
193  for idx = 1:length(filename_tmp)
194  character = filename_tmp(idx);
195  comp = find(strcmp( character, numerics ));
196 
197  if norm(comp) > 0
198  if isempty( start_idx )
199  start_idx = idx;
200  end
201  else
202  if isempty( end_idx ) && ~isempty( start_idx )
203  end_idx = idx;
204  end
205  end
206 
207 
208  if ~isempty( start_idx ) && ~isempty(end_idx )
209  number_tmp = str2double( filename_tmp(start_idx:end_idx-1) );
210  if ret < number_tmp
211  ret = number_tmp;
212  end
213  start_idx = [];
214  end_idx = [];
215  end
216 
217 
218  end
219  end
220 
221  ret = ret+1;
222 
223 
224 
225  end
226 
227 
228 end
function test(arg1, arg2)
Brief description of the function.
Fortran compatible complex type.
Definition: zgetDiagInv.c:40
function runTest(fncname, directory)
Runs the test for a specific example.
function()
Structure param contains data structures describing the physical parameters of the scattering center ...
Definition: structures.m:45
function getFilenum(directory)
Determines the up-comming 'filenum' input.
function automatic_test()
Launches the automatic test procedure. First, source code functionalities are checked by processing t...