Skip to content

Commit 8c4e438

Browse files
jcurtis2slayoo
andauthored
Add default values for AeroState::dist_sample arguments: sample_prop, create_time, allow_doubling & allow_halving (#205)
Co-authored-by: Sylwester Arabas <[email protected]>
1 parent 8a181f9 commit 8c4e438

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/pypartmc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ PYBIND11_MODULE(_PyPartMC, m) {
168168
.def("rand_particle", AeroState::get_random_particle,
169169
"returns a random particle from the population")
170170
.def("dist_sample", AeroState::dist_sample,
171-
"sample particles for AeroState from an AeroDist")
171+
"sample particles for AeroState from an AeroDist",
172+
py::arg("AeroDist"), py::arg("sample_prop") = 1.0, py::arg("create_time") = 0.0,
173+
py::arg("allow_doubling") = true, py::arg("allow_halving") = true)
172174
;
173175

174176
py::class_<GasData, std::shared_ptr<GasData>>(m, "GasData",

tests/test_aero_state.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,23 @@ def test_get_particle_out_of_range(
232232
assert False
233233

234234
@staticmethod
235-
def test_dist_sample():
235+
@pytest.mark.parametrize(
236+
"args",
237+
(
238+
(1.0, 0.0, True, True),
239+
pytest.param((), id="default args"),
240+
),
241+
)
242+
def test_dist_sample(args):
243+
# arrange
236244
n_part = 44
237245
aero_data = ppmc.AeroData(AERO_DATA_CTOR_ARG_MINIMAL)
238246
aero_dist = ppmc.AeroDist(aero_data, AERO_DIST_CTOR_ARG_MINIMAL)
239247
sut = ppmc.AeroState(n_part, aero_data)
240-
n_added = sut.dist_sample(aero_dist, 1.0, 0.0, True, True)
241248

249+
# act
250+
n_added = sut.dist_sample(aero_dist, *args)
251+
252+
# assert
242253
assert n_added > n_part * 0.5
243254
assert n_added < n_part * 2

0 commit comments

Comments
 (0)