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