This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
forked from agzimmerman/heat-source-trajectory-pcm-matlab
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.m
84 lines (83 loc) · 3.25 KB
/
test.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function test( TestDirs, Option )
%TEST runs regression tests for DIMICE.
% TEST() or TEST('Default') runs the default tests, i.e. all tests in the
% Tests directory. All child directories are found recursively.
%
% TEST(TestDirs) runs the test cases at each directory in TestDirs. This
% will not look for any child directories.
%
% TEST('Default', 'Plot') will plot the trajectories
% during tests.
Tolerance = 1e-8; % Observed errors between 64-Bit Windows and 64-Bit Linux have been as high as 1e-9.
%%
warning('This is not a full regression test. Also run examples.m before sharing.')
addpath('General')
%% Handle inputs.
if ~exist('TestDirs', 'var') || strcmp(TestDirs, 'Default')
TestRoot = 'Tests';
fprintf(['Finding all tests in directory ', TestRoot, ' -> '])
TestDirs = strsplit(genpath(TestRoot), {';',':'});
TestDirs = TestDirs(~strcmp(TestDirs, TestRoot));
TestDirs = TestDirs(~strcmp(TestDirs, ''));
TestDirs = strrep(TestDirs, '\', '/');
fprintf(['Found ', int2str(length(TestDirs)), '.\n'])
end
if ischar(TestDirs)
TestDirs = {TestDirs};
end
if exist('Option', 'var')
if strcmp(Option, 'Plot')
% This one setting in Config can be overriden, since it should be common to
% wish to see the test trajectories, though usually this is not necessary.
PlotTrajectory = true;
else
error('Option not recognized.')
end
else
PlotTrajectory = false;
end
%%
TestCount = length(TestDirs);
display(['Running ', int2str(TestCount), ' tests:'])
SkipCount = 0;
for i = 1:TestCount
TestPath = TestDirs{i};
Config = loadVar([TestPath, '/Config.mat'], 'Config');
Config.Display.PlotTrajectory = PlotTrajectory;
fprintf(['\t', int2str(i), '. ' TestPath, ' -> '])
if ~any(3:6 == exist(Config.NLP.Solver, 'file')) % see "doc exist" for why "3:6" was chosen.
warning(['Skipping test because ', Config.NLP.Solver,...
' is not in path.'])
SkipCount = SkipCount + 1;
continue
end
Results = dimice(Config);
if ~exist([TestPath, '/ExpectedResults.mat'], 'file')
error('This test is missing expected results.')
end
ExpectedResults = loadVar([TestPath, '/ExpectedResults.mat'],...
'Results');
NormError = norm(Results.X - ExpectedResults.X);
if NormError > Tolerance
error(['Test failed: norm error ', sprintf('%g', NormError),...
' greater than tolerance ', sprintf('%g', Tolerance)])
end
OtherComputer = ExpectedResults.Properties.UserData.Computer;
% Nullify the UserData to easily compare the numerical results.
ExpectedResults.Properties.UserData = [];
Results.Properties.UserData = [];
if ~isequal(Results, ExpectedResults)
Message = ['Results are not exactly as expected, ',...
'but the error norm ', sprintf('%g', NormError),...
' is within the tolerance ', sprintf('%g', Tolerance), '.'];
if ~strcmp(computer, OtherComputer)
Message = [Message, 'You are using computer ', computer,...
'; the results were generated with computer ',...
OtherComputer, '.']; %#ok<AGROW>
end
warning(Message)
end
fprintf('Success.\n')
end
display(['All tests passed! (Skipped ', int2str(SkipCount), ')'])
end