diff --git a/include/open_atmos/mechanism_configuration/validation.hpp b/include/open_atmos/mechanism_configuration/validation.hpp index ff4224f..6f5de43 100644 --- a/include/open_atmos/mechanism_configuration/validation.hpp +++ b/include/open_atmos/mechanism_configuration/validation.hpp @@ -86,7 +86,7 @@ namespace open_atmos struct Arrhenius { const std::vector required_keys{ keys.products, keys.reactants, keys.type, keys.gas_phase }; - const std::vector optional_keys{ keys.A, keys.B, keys.C, keys.D, keys.E, keys.name }; + const std::vector optional_keys{ keys.A, keys.B, keys.C, keys.D, keys.E, keys.Ea, keys.name }; } arrhenius; struct Mechanism diff --git a/src/parser.cpp b/src/parser.cpp index 440830f..6bc9552 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -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); @@ -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); @@ -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; } diff --git a/test/integration/test_json_parser.cpp b/test/integration/test_json_parser.cpp index 1a73d81..c49b2de 100644 --- a/test/integration/test_json_parser.cpp +++ b/test/integration/test_json_parser.cpp @@ -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); } \ No newline at end of file diff --git a/test/unit/test_parse_arrhenius.cpp b/test/unit/test_parse_arrhenius.cpp index ebe5a52..e26fba1 100644 --- a/test/unit/test_parse_arrhenius.cpp +++ b/test/unit/test_parse_arrhenius.cpp @@ -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); } \ No newline at end of file diff --git a/test/unit/unit_configs/reactions/arrhenius/bad_reaction_component.json b/test/unit/unit_configs/reactions/arrhenius/bad_reaction_component.json new file mode 100644 index 0000000..859209d --- /dev/null +++ b/test/unit/unit_configs/reactions/arrhenius/bad_reaction_component.json @@ -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" + } + ] + } + ] +} \ No newline at end of file diff --git a/test/unit/unit_configs/reactions/arrhenius/mutually_exclusive.json b/test/unit/unit_configs/reactions/arrhenius/mutually_exclusive.json new file mode 100644 index 0000000..61db970 --- /dev/null +++ b/test/unit/unit_configs/reactions/arrhenius/mutually_exclusive.json @@ -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 + } + ] +} \ No newline at end of file