-
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 #28 from open-atmos/parse_first_order_loss
Parse first order loss
- Loading branch information
Showing
13 changed files
with
351 additions
and
2 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,57 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <open_atmos/mechanism_configuration/parser.hpp> | ||
|
||
using namespace open_atmos::mechanism_configuration; | ||
|
||
TEST(JsonParser, CanParseValidFirstOrderLossReaction) | ||
{ | ||
JsonParser parser; | ||
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/first_order_loss/valid.json")); | ||
EXPECT_EQ(status, ConfigParseStatus::Success); | ||
|
||
EXPECT_EQ(mechanism.reactions.first_order_loss.size(), 2); | ||
|
||
EXPECT_EQ(mechanism.reactions.first_order_loss[0].gas_phase, "gas"); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[0].name, "my first order loss"); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[0].scaling_factor_, 12.3); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[0].reactants.size(), 1); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[0].reactants[0].species_name, "C"); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[0].reactants[0].coefficient, 1); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[0].unknown_properties.size(), 1); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[0].unknown_properties["__comment"], "\"Strawberries are the superior fruit\""); | ||
|
||
EXPECT_EQ(mechanism.reactions.first_order_loss[1].gas_phase, "gas"); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[1].scaling_factor_, 1); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[1].reactants.size(), 1); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[1].reactants[0].species_name, "C"); | ||
EXPECT_EQ(mechanism.reactions.first_order_loss[1].reactants[0].coefficient, 1); | ||
} | ||
|
||
TEST(JsonParser, FirstOrderLossDetectsUnknownSpecies) | ||
{ | ||
JsonParser parser; | ||
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/first_order_loss/unknown_species.json")); | ||
EXPECT_EQ(status, ConfigParseStatus::ReactionRequiresUnknownSpecies); | ||
} | ||
|
||
TEST(JsonParser, FirstOrderLossDetectsBadReactionComponent) | ||
{ | ||
JsonParser parser; | ||
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/first_order_loss/bad_reaction_component.json")); | ||
EXPECT_EQ(status, ConfigParseStatus::RequiredKeyNotFound); | ||
} | ||
|
||
TEST(JsonParser, FirstOrderLossDetectsUnknownPhase) | ||
{ | ||
JsonParser parser; | ||
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/first_order_loss/missing_phase.json")); | ||
EXPECT_EQ(status, ConfigParseStatus::UnknownPhase); | ||
} | ||
|
||
TEST(JsonParser, FirstOrderLossDetectsMoreThanOneSpecies) | ||
{ | ||
JsonParser parser; | ||
auto [status, mechanism] = parser.Parse(std::string("unit_configs/reactions/first_order_loss/too_many_reactants.json")); | ||
EXPECT_EQ(status, ConfigParseStatus::TooManyReactionComponents); | ||
} |
32 changes: 32 additions & 0 deletions
32
test/unit/unit_configs/reactions/first_order_loss/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,32 @@ | ||
{ | ||
"version": "1.0.0", | ||
"name": "Bad reaction component", | ||
"species": [ | ||
{ | ||
"name": "A" | ||
}, | ||
{ | ||
"name": "B" | ||
} | ||
], | ||
"phases": [ | ||
{ | ||
"name": "gas", | ||
"species": [ | ||
"A", | ||
"B" | ||
] | ||
} | ||
], | ||
"reactions": [ | ||
{ | ||
"type": "FIRST_ORDER_LOSS", | ||
"gas phase": "gas", | ||
"reactants": [ | ||
{ | ||
"Species name": "C" | ||
} | ||
] | ||
} | ||
] | ||
} |
27 changes: 27 additions & 0 deletions
27
test/unit/unit_configs/reactions/first_order_loss/missing_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,27 @@ | ||
{ | ||
"version": "1.0.0", | ||
"name": "Missing phase", | ||
"species": [ | ||
{ | ||
"name": "A" | ||
}, | ||
{ | ||
"name": "B" | ||
}, | ||
{ | ||
"name": "C" | ||
} | ||
], | ||
"phases": [ ], | ||
"reactions": [ | ||
{ | ||
"type": "FIRST_ORDER_LOSS", | ||
"gas phase": "gas", | ||
"reactants": [ | ||
{ | ||
"species name": "C" | ||
} | ||
] | ||
} | ||
] | ||
} |
41 changes: 41 additions & 0 deletions
41
test/unit/unit_configs/reactions/first_order_loss/too_many_reactants.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,41 @@ | ||
{ | ||
"version": "1.0.0", | ||
"name": "Too many reactants", | ||
"species": [ | ||
{ | ||
"name": "A" | ||
}, | ||
{ | ||
"name": "B" | ||
}, | ||
{ | ||
"name": "C" | ||
} | ||
], | ||
"phases": [ | ||
{ | ||
"name": "gas", | ||
"species": [ | ||
"A", | ||
"B", | ||
"C" | ||
] | ||
} | ||
], | ||
"reactions": [ | ||
{ | ||
"type": "FIRST_ORDER_LOSS", | ||
"gas phase": "gas", | ||
"reactants": [ | ||
{ | ||
"species name": "C", | ||
"coefficient": 1 | ||
}, | ||
{ | ||
"species name": "B", | ||
"coefficient": 1 | ||
} | ||
] | ||
} | ||
] | ||
} |
32 changes: 32 additions & 0 deletions
32
test/unit/unit_configs/reactions/first_order_loss/unknown_species.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,32 @@ | ||
{ | ||
"version": "1.0.0", | ||
"name": "Unknown species", | ||
"species": [ | ||
{ | ||
"name": "A" | ||
}, | ||
{ | ||
"name": "B" | ||
} | ||
], | ||
"phases": [ | ||
{ | ||
"name": "gas", | ||
"species": [ | ||
"A", | ||
"B" | ||
] | ||
} | ||
], | ||
"reactions": [ | ||
{ | ||
"type": "FIRST_ORDER_LOSS", | ||
"gas phase": "gas", | ||
"reactants": [ | ||
{ | ||
"species name": "C" | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.