[MATLAB] Added invalid input tests

This commit is contained in:
ssun30 2025-02-12 23:31:46 -05:00
parent 0a2e220d50
commit 59ccae1258
3 changed files with 174 additions and 9 deletions

View File

@ -0,0 +1,64 @@
phases:
- name: A
thermo: ideal-gas
species: [{h2o2.yaml/species: all}]
kinetics: gas
state: {T: 300.0, P: 1 atm, X: {O2: 0.21, N2: 0.79}}
reactions: [A-reactions]
- name: B
thermo: ideal-gas
species: [{h2o2.yaml/species: all}]
kinetics: gas
state: {T: 300.0, P: 1 atm, X: {O2: 0.21, N2: 0.79}}
reactions: [B-reactions]
- name: C
thermo: ideal-gas
species: [{h2o2.yaml/species: all}]
kinetics: gas
state: {T: 300.0, P: 1 atm, X: {O2: 0.21, N2: 0.79}}
reactions: [C-reactions]
- name: D
thermo: ideal-gas
species: [{h2o2.yaml/species: all}]
kinetics: gas
state: {T: 300.0, P: 1 atm, X: {O2: 0.21, N2: 0.79}}
reactions: [D-reactions]
- name: E
thermo: ideal-gas
species: [{h2o2.yaml/species: all}]
kinetics: gas
state: {T: 300.0, P: 1 atm, X: {O2: 0.21, N2: 0.79}}
reactions: [E-reactions]
- name: F
thermo: ideal-gas
species: [{h2o2.yaml/species: all}]
kinetics: gas
state: {T: 300.0, P: 1 atm, X: {O2: 0.21, N2: 0.79}}
reactions: [F-reactions]
A-reactions:
- equation: O + H2 <=> H + OH # Reaction 3
rate-constant: {A: 3.87e+04 cm^6/mol^2/s, b: 2.7, Ea: 6260.0}
B-reactions:
- equation: O + H2 <=> H + OH # Reaction 3
rate-constant: {A: 3.87e+04, b: 2.7, Ea: 6260.0 m}
C-reactions:
- equation: O + H2 <=> H + OH
D-reactions:
- equation: 2 OH (+M) <=> H2O2 (+M)
type: falloff
E-reactions:
- equation: O + H2 <=> H + OH
type: pressure-dependent-Arrhenius
F-reactions:
- equation: O + H2 <=> H + OH
rate-constant: {A: 3.87e+04, b: 2.7, Ea: 6260.0}
duplicate: true
- equation: O + H2 <=> H + OH
rate-constant: {A: -3.87e+04, b: 2.7, Ea: 6260.0}
duplicate: true

View File

@ -0,0 +1,97 @@
classdef ctTestInvalidInputs < matlab.unittest.TestCase
properties
phase
end
properties (SetAccess = immutable)
inputfile = 'invalid-inputs.yaml';
end
methods (TestClassSetup)
function testSetUp(self)
copyfile('../data/invalid-inputs.yaml', ...
'./invalid-inputs.yaml');
ctTestSetUp
end
end
methods (TestClassTeardown)
function testTearDown(self)
delete('./invalid-inputs.yaml');
ctCleanUp
ctTestTearDown
end
end
methods (TestMethodTeardown)
function deleteSolution(self)
clear self.phase;
end
end
methods (Test)
function testFailingConvert1(self)
try
self.phase = Solution(self.inputfile, 'A');
catch ME
self.verifySubstring(ME.identifier, 'Cantera:ctError');
self.verifySubstring(ME.message, 'UnitSystem::convert');
end
end
function testFailingConvert2(self)
try
self.phase = Solution(self.inputfile, 'B');
catch ME
self.verifySubstring(ME.identifier, 'Cantera:ctError');
self.verifySubstring(ME.message, 'UnitSystem::convertActivationEnergy');
end
end
function testFailingUnconfigured1(self)
try
self.phase = Solution(self.inputfile, 'C');
catch ME
self.verifySubstring(ME.identifier, 'Cantera:ctError');
self.verifySubstring(ME.message, 'ArrheniusBase::validate');
end
end
function testFailingUnconfigured2(self)
try
self.phase = Solution(self.inputfile, 'D');
catch ME
self.verifySubstring(ME.identifier, 'Cantera:ctError');
self.verifySubstring(ME.message, 'FalloffRate::validate');
end
end
function testFailingUnconfigured3(self)
try
self.phase = Solution(self.inputfile, 'E');
catch ME
self.verifySubstring(ME.identifier, 'Cantera:ctError');
self.verifySubstring(ME.message, 'PlogRate::validate');
end
end
function testFailingInvalidDuplicate(self)
try
self.phase = Solution(self.inputfile, 'F');
catch ME
self.verifySubstring(ME.identifier, 'Cantera:ctError');
self.verifySubstring(ME.message, 'ArrheniusBase::check');
self.verifySubstring(ME.message, 'negative pre-exponential factor');
end
end
end
end

View File

@ -4,6 +4,10 @@ classdef ctTestUndeclared < matlab.unittest.TestCase
phase
end
properties (SetAccess = immutable)
inputfile = 'undeclared-tests.yaml';
end
methods (TestClassSetup)
function testSetUp(self)
@ -36,7 +40,7 @@ classdef ctTestUndeclared < matlab.unittest.TestCase
function testRaiseUndeclaredSpecies(self)
try
self.phase = Solution('undeclared-tests.yaml', 'A');
self.phase = Solution(self.inputfile, 'A');
catch ME
self.verifySubstring(ME.identifier, 'Cantera:ctError');
self.verifySubstring(ME.message, 'contains undeclared species');
@ -45,7 +49,7 @@ classdef ctTestUndeclared < matlab.unittest.TestCase
function testRaiseUndeclaredThirdBodies(self)
try
self.phase = Solution('undeclared-tests.yaml', 'B');
self.phase = Solution(self.inputfile, 'B');
catch ME
self.verifySubstring(ME.identifier, 'Cantera:ctError');
self.verifySubstring(ME.message, 'three-body reaction with undeclared');
@ -53,24 +57,24 @@ classdef ctTestUndeclared < matlab.unittest.TestCase
end
function testSkipUndeclaredThirdBodies1(self)
self.phase = Solution('undeclared-tests.yaml', 'C');
self.phase = Solution(self.inputfile, 'C');
self.verifyEqual(self.phase.nReactions, 3);
end
function testSkipUndeclaredThirdBodies2(self)
self.phase = Solution('undeclared-tests.yaml', 'D');
self.phase = Solution(self.inputfile, 'D');
rxns = self.phase.reactionEquations;
self.verifyTrue(ismember('H + O2 + M <=> HO2 + M', rxns));
end
function testSkipUndeclaredOrders(self)
self.phase = Solution('undeclared-tests.yaml', 'E');
self.phase = Solution(self.inputfile, 'E');
self.verifyEqual(self.phase.nReactions, 1);
end
function testRaiseNonreactantOrders(self)
try
self.phase = Solution('undeclared-tests.yaml', 'F');
self.phase = Solution(self.inputfile, 'F');
catch ME
self.verifySubstring(ME.identifier, 'Cantera:ctError');
self.verifySubstring(ME.message, 'Reaction order specified');
@ -79,7 +83,7 @@ classdef ctTestUndeclared < matlab.unittest.TestCase
function testRaiseUndeclaredOrders(self)
try
self.phase = Solution('undeclared-tests.yaml', 'G');
self.phase = Solution(self.inputfile, 'G');
catch ME
self.verifySubstring(ME.identifier, 'Cantera:ctError');
self.verifySubstring(ME.message, 'reaction orders for undeclared');
@ -88,8 +92,8 @@ classdef ctTestUndeclared < matlab.unittest.TestCase
function testSkipUndeclaredSurfSpecies(self)
try
gas = Solution('undeclared-tests.yaml', 'gas');
surf = Interface('undeclared-tests.yaml', 'Pt_surf', gas);
gas = Solution(self.inputfile, 'gas');
surf = Interface(self.inputfile, 'Pt_surf', gas);
self.verifyEqual(surf.nReactions, 14);
clear gas