Skip to content

Commit

Permalink
error detection
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Jan 17, 2024
1 parent f9e2eb9 commit f351163
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/open_atmos/mechanism_configuration/validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace open_atmos
struct Arrhenius
{
const std::vector<std::string> required_keys{ keys.products, keys.reactants, keys.type, keys.gas_phase };
const std::vector<std::string> optional_keys{ keys.A, keys.B, keys.C, keys.D, keys.E, keys.name };
const std::vector<std::string> optional_keys{ keys.A, keys.B, keys.C, keys.D, keys.E, keys.Ea, keys.name };
} arrhenius;

struct Mechanism
Expand Down
8 changes: 5 additions & 3 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ namespace open_atmos
for (const auto& product : object[validation::keys.products])
{
auto product_parse = ParseReactionComponent(product);
if (product_parse.first != ConfigParseStatus::Success) {
status = product_parse.first;
if (status != ConfigParseStatus::Success) {
break;
}
products.push_back(product_parse.second);
Expand All @@ -327,7 +328,8 @@ namespace open_atmos
for (const auto& reactant : object[validation::keys.reactants])
{
auto reactant_parse = ParseReactionComponent(reactant);
if (reactant_parse.first != ConfigParseStatus::Success) {
status = reactant_parse.first;
if (status != ConfigParseStatus::Success) {
break;
}
reactants.push_back(reactant_parse.second);
Expand Down Expand Up @@ -386,7 +388,7 @@ namespace open_atmos
requested_species.push_back(spec.species_name);
}

if (RequiresUnknownSpecies(requested_species, existing_species)) {
if (status == ConfigParseStatus::Success && RequiresUnknownSpecies(requested_species, existing_species)) {
status = ConfigParseStatus::ReactionRequiresUnknownSpecies;
}

Expand Down
7 changes: 7 additions & 0 deletions test/integration/test_json_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ TEST(JsonParser, ParsesFullConfiguration)
EXPECT_EQ(mechanism.name, "Full Configuration");
EXPECT_EQ(mechanism.species.size(), 10);
EXPECT_EQ(mechanism.reactions.arrhenius.size(), 1);
}

TEST(JsonParser, ParserReportsBadFiles)
{
JsonParser parser;
auto [status, mechanism] = parser.Parse(std::string("examples/_missing_configuration.json"));
EXPECT_EQ(status, ConfigParseStatus::InvalidFilePath);
}
14 changes: 14 additions & 0 deletions test/unit/test_parse_arrhenius.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,18 @@ TEST(JsonParser, ArrheniusDetectsUnknownSpecies)
JsonParser parser;
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/arrhenius/unknown_species.json"));
EXPECT_EQ(status, ConfigParseStatus::ReactionRequiresUnknownSpecies);
}

TEST(JsonParser, ArrheniusDetectsMutuallyExclusiveOptions)
{
JsonParser parser;
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/arrhenius/mutually_exclusive.json"));
EXPECT_EQ(status, ConfigParseStatus::MutuallyExclusiveOption);
}

TEST(JsonParser, ArrheniusDetectsBadReactionComponent)
{
JsonParser parser;
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/arrhenius/bad_reaction_component.json"));
EXPECT_EQ(status, ConfigParseStatus::RequiredKeyNotFound);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"version": "1.0.0",
"name": "Mutually Exclusive",
"species": [
{
"name": "A"
},
{
"name": "B"
}
],
"phases": [
{
"name": "gas",
"species": [
"A",
"B"
]
}
],
"reactions": [
{
"type": "ARRHENIUS",
"gas phase": "gas",
"reactants": [
{
"Species name": "A"
}
],
"products": [
{
"species name": "B"
}
]
}
]
}
39 changes: 39 additions & 0 deletions test/unit/unit_configs/reactions/arrhenius/mutually_exclusive.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": "1.0.0",
"name": "Mutually Exclusive",
"species": [
{
"name": "A"
},
{
"name": "B"
}
],
"phases": [
{
"name": "gas",
"species": [
"A",
"B"
]
}
],
"reactions": [
{
"type": "ARRHENIUS",
"gas phase": "gas",
"reactants": [
{
"species name": "A"
}
],
"products": [
{
"species name": "B"
}
],
"C": 10,
"Ea": 0.5
}
]
}

0 comments on commit f351163

Please sign in to comment.