Skip to content

Commit

Permalink
add a check for presence of size_dist
Browse files Browse the repository at this point in the history
  • Loading branch information
slayoo committed Apr 26, 2024
1 parent 1186a3b commit bdb0270
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/aero_mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ struct AeroMode {
throw std::runtime_error("mass_frac value must be a list of single-element dicts");
if (!InputJSONResource::unique_keys(mass_frac))
throw std::runtime_error("mass_frac keys must be unique");
if (mode["mode_type"] == "sampled") {
if (mode.find("size_dist") == mode.end())
throw std::runtime_error("size_dist key must be set for mode_type=sampled");
}
}

static auto get_num_conc(const AeroMode &self){
Expand Down
14 changes: 14 additions & 0 deletions tests/test_aero_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,20 @@ def test_segfault_case(): # TODO #319
print(fishy_ctor_arg)
ppmc.AeroMode(aero_data, fishy_ctor_arg)

@staticmethod
def test_sampled_without_size_dist():
# arrange
aero_data = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL)
fishy_ctor_arg = copy.deepcopy(AERO_MODE_CTOR_LOG_NORMAL)
fishy_ctor_arg["test_mode"]["mode_type"] = "sampled"

# act
with pytest.raises(Exception) as exc_info:
ppmc.AeroMode(aero_data, fishy_ctor_arg)

# assert
assert str(exc_info.value) == "size_dist key must be set for mode_type=sampled"

@staticmethod
def test_sampled():
# arrange
Expand Down

0 comments on commit bdb0270

Please sign in to comment.