-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from open-atmos/parse_surface
Parse surface
- Loading branch information
Showing
12 changed files
with
408 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <open_atmos/mechanism_configuration/parser.hpp> | ||
|
||
using namespace open_atmos::mechanism_configuration; | ||
|
||
TEST(JsonParser, CanParseValidSurfaceReaction) | ||
{ | ||
JsonParser parser; | ||
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/surface/valid.json")); | ||
EXPECT_EQ(status, ConfigParseStatus::Success); | ||
|
||
EXPECT_EQ(mechanism.reactions.surface.size(), 2); | ||
|
||
EXPECT_EQ(mechanism.reactions.surface[0].gas_phase, "gas"); | ||
EXPECT_EQ(mechanism.reactions.surface[0].name, "my surface"); | ||
EXPECT_EQ(mechanism.reactions.surface[0].aerosol_phase, "surface reacting phase"); | ||
EXPECT_EQ(mechanism.reactions.surface[0].reaction_probability, 2.0e-2); | ||
EXPECT_EQ(mechanism.reactions.surface[0].gas_phase_reactant.species_name, "A"); | ||
EXPECT_EQ(mechanism.reactions.surface[0].gas_phase_reactant.coefficient, 1); | ||
EXPECT_EQ(mechanism.reactions.surface[0].gas_phase_products.size(), 2); | ||
EXPECT_EQ(mechanism.reactions.surface[0].gas_phase_products[0].species_name, "B"); | ||
EXPECT_EQ(mechanism.reactions.surface[0].gas_phase_products[0].coefficient, 1); | ||
EXPECT_EQ(mechanism.reactions.surface[0].gas_phase_products[1].species_name, "C"); | ||
EXPECT_EQ(mechanism.reactions.surface[0].gas_phase_products[1].coefficient, 1); | ||
EXPECT_EQ(mechanism.reactions.surface[0].unknown_properties.size(), 1); | ||
EXPECT_EQ(mechanism.reactions.surface[0].unknown_properties["__comment"], "\"key lime pie is superior to all other pies\""); | ||
|
||
EXPECT_EQ(mechanism.reactions.surface[1].gas_phase, "gas"); | ||
EXPECT_EQ(mechanism.reactions.surface[1].aerosol_phase, "surface reacting phase"); | ||
EXPECT_EQ(mechanism.reactions.surface[1].reaction_probability, 1.0); | ||
EXPECT_EQ(mechanism.reactions.surface[1].gas_phase_reactant.species_name, "A"); | ||
EXPECT_EQ(mechanism.reactions.surface[1].gas_phase_reactant.coefficient, 1); | ||
EXPECT_EQ(mechanism.reactions.surface[1].gas_phase_products.size(), 2); | ||
EXPECT_EQ(mechanism.reactions.surface[1].gas_phase_products[0].species_name, "B"); | ||
EXPECT_EQ(mechanism.reactions.surface[1].gas_phase_products[0].coefficient, 1); | ||
EXPECT_EQ(mechanism.reactions.surface[1].gas_phase_products[0].unknown_properties.size(), 1); | ||
EXPECT_EQ(mechanism.reactions.surface[1].gas_phase_products[0].unknown_properties["__optional thing"], "\"hello\""); | ||
EXPECT_EQ(mechanism.reactions.surface[1].gas_phase_products[1].species_name, "C"); | ||
EXPECT_EQ(mechanism.reactions.surface[1].gas_phase_products[1].coefficient, 1); | ||
} | ||
|
||
TEST(JsonParser, SurfaceDetectsUnknownSpecies) | ||
{ | ||
JsonParser parser; | ||
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/surface/unknown_species.json")); | ||
EXPECT_EQ(status, ConfigParseStatus::ReactionRequiresUnknownSpecies); | ||
} | ||
|
||
TEST(JsonParser, SurfaceDetectsBadReactionComponent) | ||
{ | ||
JsonParser parser; | ||
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/surface/bad_reaction_component.json")); | ||
EXPECT_EQ(status, ConfigParseStatus::RequiredKeyNotFound); | ||
} | ||
|
||
TEST(JsonParser, SurfaceDetectsUnknownPhase) | ||
{ | ||
JsonParser parser; | ||
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/surface/missing_aerosol_phase.json")); | ||
EXPECT_EQ(status, ConfigParseStatus::UnknownPhase); | ||
} |
45 changes: 45 additions & 0 deletions
45
test/unit/unit_configs/reactions/surface/bad_reaction_component.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"version": "1.0.0", | ||
"name": "Bad reaction component", | ||
"species": [ | ||
{ | ||
"name": "A" | ||
}, | ||
{ | ||
"name": "B" | ||
} | ||
], | ||
"phases": [ | ||
{ | ||
"name": "gas", | ||
"species": [ | ||
"A", | ||
"B" | ||
] | ||
} | ||
], | ||
"reactions": [ | ||
{ | ||
"type": "SURFACE", | ||
"gas phase": "gas", | ||
"gas-phase reactant": { | ||
"Species name": "A", | ||
"coefficient": 1 | ||
}, | ||
"reaction probability": 2.0e-2, | ||
"gas-phase products": [ | ||
{ | ||
"species name": "B", | ||
"coefficient": 1 | ||
}, | ||
{ | ||
"species name": "C", | ||
"coefficient": 1 | ||
} | ||
], | ||
"aerosol phase": "surface reacting phase", | ||
"name": "my surface", | ||
"__coment" : "key lime pie is superior to all other pies" | ||
} | ||
] | ||
} |
45 changes: 45 additions & 0 deletions
45
test/unit/unit_configs/reactions/surface/missing_aerosol_phase.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"version": "1.0.0", | ||
"name": "Missing aerosol phase", | ||
"species": [ | ||
{ | ||
"name": "A" | ||
}, | ||
{ | ||
"name": "B" | ||
}, | ||
{ | ||
"name": "C" | ||
} | ||
], | ||
"phases": [ | ||
{ | ||
"name": "gas", | ||
"species": [ | ||
"A", | ||
"B", | ||
"C" | ||
] | ||
} | ||
], | ||
"reactions": [ | ||
{ | ||
"type": "SURFACE", | ||
"gas phase": "gas", | ||
"gas-phase reactant": { | ||
"species name": "A", | ||
"coefficient": 1 | ||
}, | ||
"gas-phase products": [ | ||
{ | ||
"species name": "B", | ||
"__optional thing": "hello" | ||
}, | ||
{ | ||
"species name": "C" | ||
} | ||
], | ||
"aerosol phase": "surface reacting phase" | ||
} | ||
] | ||
} |
Oops, something went wrong.