Skip to content

Commit

Permalink
pass out the custom failures
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin committed Sep 21, 2023
1 parent c3bf008 commit 740f2c6
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 134 deletions.
12 changes: 7 additions & 5 deletions vbr/testing/run_tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,18 @@
for ifile = 1:numel(mfiles)
fname=mfiles(ifile).name;
if ~strcmp('run_tests.m',fname)
[fdir,funcname,ext]=fileparts(fname);

[fdir,funcname,ext]=fileparts(fname);
disp([' **** Running ', funcname, ' ****'])
if any(strcmp(test_config.matlab_only, funcname)) && isOctave
SkippedTests.(funcname) = "MATLAB Only";
else

try
testResult=feval(funcname);
test_error = struct();
if testResult>0
test_error.message = testResult.fail_message;
test_error.identifier = 'VBRc_TEST_ERROR';
if testResult.passed>0
disp(' test passed :D'); disp(' ')
else
failedCount=failedCount+1;
Expand All @@ -113,10 +115,10 @@
disp(' ')
disp([' ', err_id, ': ', err_msg])
disp(' ')
testResult=false;
testResult.passed=false;
failedCount=failedCount+1;
end
TestResults.(funcname)=testResult;
TestResults.(funcname)=testResult.passed;
ErrorMessages.(funcname) = test_error;
end
end
Expand Down
8 changes: 5 additions & 3 deletions vbr/testing/test_fm_plates_001.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_001 ****')

% Load Default Settings
[settings]=init_settings;
Expand Down Expand Up @@ -42,5 +43,6 @@
% Lithosphere temperature evolution
[Vars,Info]=Thermal_Evolution(Info,settings);

TestResult=true;
TestResult.passed=true;
TestResult.fail_message = '';
end
23 changes: 14 additions & 9 deletions vbr/testing/test_fm_plates_002.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_002 ****')
disp(' (takes a few minutes)')
TestResult=true;
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TestResult.passed=true;
TestResult.fail_message = '';
% Load Default Settings
[settings]=init_settings;

Expand Down Expand Up @@ -53,8 +54,10 @@
% get the diffusivity (make sure it's constant)
kappa=Vars.Kc ./ (Vars.rho .* Vars.cp);
if min(kappa(:))<max(kappa(:))
TestResult=false;
disp(' diffusivity is not constant!!!!!')
TestResult.passed=false;
msg = ' diffusivity is not constant!!!!!';
TestResult.fail_message = msg;
disp(msg)
end
kappa=min(kappa(:));

Expand All @@ -73,8 +76,10 @@
t_cutoffs=[5,Info.tMyrs(end)]; % min/max for transient h space soln
tmask=(Info.tMyrs>=t_cutoffs(1))&(Info.tMyrs<=t_cutoffs(2));
if sum(max_err(tmask)>max_err_tol)
disp(' half space cooling solution incorrect!!!!!')
TestResult=false;
msg = ' half space cooling solution incorrect!!!!!';
TestResult.passed=false;
TestResult.fail_message = msg;
disp(msg)
end

end
17 changes: 10 additions & 7 deletions vbr/testing/test_fm_plates_003.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_003 ****')
disp(' (takes <1 minute)')
TestResult=true;
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TestResult.passed =true;
TestResult.fail_message = '';
% Load Default Settings
[settings]=init_settings;

Expand Down Expand Up @@ -56,7 +57,9 @@
% check if it passes
max_err_tol=1e-5;
if max_err_tol>max_err_tol
disp(' steady state plate solution incorrect!!!!!')
TestResult=false;
msg = ' steady state plate solution incorrect!!!!!'
disp(msg)
TestResult.passed=false;
TestResult.fail_message = msg;
end
end
16 changes: 9 additions & 7 deletions vbr/testing/test_fm_plates_004_solidus.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_004_solidus ****')

% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Note that the SoLiquidus function now lives in the vbrCore/functions/thermal_properties/
% directory.

TestResult=true;
% directory.

TestResult.passed =true;
TestResult.fail_message = '';

F = 0.05;
z = linspace(0,200,100)*1e3;
Expand Down
9 changes: 6 additions & 3 deletions vbr/testing/test_fm_plates_005_box.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_005_box ****')
TestResult=true;

TestResult.passed =true;
TestResult.fail_message = '';
% Parameter sweep settings
% define parameter sweep here. var1name must match EXACTLY a field in
% settings structure. var1 must be defined, var2 lines can be
Expand Down
32 changes: 21 additions & 11 deletions vbr/testing/test_fm_plates_006_thermoprops.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_fm_plates_006_thermoprops ****')
TestResult=true;

TestResult.passed =true;
TestResult.fail_message = '';

z=transpose(linspace(0,400,100)*1e3);
P0=1e5;
Expand All @@ -25,7 +28,7 @@
T=1400*z/z_L;
T(z>z_L)=(z(z>z_L)-z_L) * dTdz_ad + max(T(z<=z_L));
T=T+273;
PropTypes= {'con';'P_dep';'T_dep';'PT_dep'};
PropTypes= {'con';'P_dep';'T_dep';'PT_dep'};
P1=zeros(numel(z),4);
P2=zeros(numel(z),4);

Expand All @@ -37,14 +40,21 @@
% [Rho,Cp,Kc,P]
diff=sum(abs(P1(:)-P2(:))./P1(:));
if diff > 0
TestResult=false;
disp(' ThermodynamicProps not matching MaterialProperties')
TestResult.passed=false;
msg = ' ThermodynamicProps not matching MaterialProperties';
TestResult.fail_message = msg;
disp(msg)
elseif sum(isnan(P1))>0
TestResult=false;
disp(' ThermodynamicProps solution contains nans')
elseif sum(isnan(P2))>0
TestResult=false;
disp(' MaterialProperties solution contains nans')
TestResult.passed=false;
msg = ' ThermodynamicProps solution contains nans';
disp(msg)
TestResult.fail_message = msg;
% elseif sum(isnan(P2))>0
else
TestResult.passed=false;
msg = ' MaterialProperties solution contains nans';
disp(msg)
TestResult.fail_message = msg;
end
end

Expand Down
14 changes: 9 additions & 5 deletions vbr/testing/test_matlab_only_test_trigger.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

TestResult=true;
disp(' **** Running test_matlab_only_test_trigger ****')
TestResult.passed =true;
TestResult.fail_message = '';

isOctave = is_octave();

if isOctave
TestResult = false;
disp(" This test is MATLAB only, but Octave is running it..")
TestResult.passed = false;
msg = " This test is MATLAB only, but Octave is running it...";
disp(msg);
TestResult.fail_message = msg;
end


Expand Down
51 changes: 30 additions & 21 deletions vbr/testing/test_vbr_units.m
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
function TestResult = test_vbr_units()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% check that attach_input_metadata works as expected
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

disp(' **** Running test_vbr_units ****')

% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

units = SV_input_units(); % check that it runs

VBR = struct();
VBR.in = struct();
VBR.in.SV = struct();
VBR.in.SV.T_K = 1;
VBR.in.SV.phi = 0.01;
VBR.in.SV.T_K = 1;
VBR.in.SV.phi = 0.01;
VBR.in.SV.P_GPa = 1;
VBR.in.SV.not_a_field = 0;
VBR = attach_input_metadata(VBR);
TestResult = true;
TestResult.passed = true;
TestResult.fail_message = '';
if isfield(VBR.in.SV, 'units')
if isfield(VBR.in.SV.units, "not_a_field")
disp(" unknown field should not be in sv_metadata")
TestResult = false;
msg = " unknown field should not be in sv_metadata";
disp(msg)
TestResult.passed = false;
TestResult.fail_message = msg;
else
if strcmp(VBR.in.SV.units.T_K, "Kelvin") == 0
disp(" Incorrect units.")
TestResult = false;
if strcmp(VBR.in.SV.units.T_K, "Kelvin") == 0
msg = " Incorrect units.";
TestResult.passed = false;
TestResult.fail_message = msg;
disp(msg)
end
end
end
else
TestResult = false;
TestResult.passed = false;
TestResult.fail_message = ' missing VBR.in.SV.units ';
end
% also check that the units gets attached to the VBR in a call to spine

% also check that the units gets attached to the VBR in a call to spine
VBR.in.elastic.methods_list={'anharmonic'};

% Define the Thermodynamic State
n1 = 3;
n2 = 5;
Expand All @@ -42,7 +49,9 @@

VBR = VBR_spine(VBR);
if isfield(VBR.in.SV, 'units') == 0
disp(' VBR.in.SV is missing units')
TestResult = false;
msg = ' VBR.in.SV is missing units';
TestResult.passed = false;
TestResult.fail_message = msg;
disp(msg)
end
end
end
28 changes: 18 additions & 10 deletions vbr/testing/test_vbr_version.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@
%
% Output
% ------
% TestResult True if passed, False otherwise.
% TestResult struct with fields:
% .passed True if passed, False otherwise.
% .fail_message Message to display if false
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(' **** Running test_vbr_version ****')

version = vbr_version();
TestResult.passed = true;
TestResult.fail_message = '';
if isfield(version, 'version')
TestResult = true;
TestResult.passed = true;
else
disp(' vbr_version output missing version field')
TestResult = false;
TestResult.passed = false;
msg = ' vbr_version output missing version field'
disp(msg)
TestResult.fail_message = msg;
end
% also check that the version gets attached to the VBR in a call

% also check that the version gets attached to the VBR in a call
VBR.in.elastic.methods_list={'anharmonic'};

% Define the Thermodynamic State
n1 = 3;
n2 = 5;
Expand All @@ -33,7 +39,9 @@

VBR = VBR_spine(VBR);
if isfield(VBR, 'version_used') == 0
disp(' VBR structure is missing version_used field')
TestResult = false;
msg = ' VBR structure is missing version_used field'
TestResult.passed = false;
disp(msg)
TestResult.fail_message = msg;
end
end
Loading

0 comments on commit 740f2c6

Please sign in to comment.