Skip to content

Commit 729c7d9

Browse files
authored
Add test for test_bin_average_comp (#324)
1 parent 21def14 commit 729c7d9

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

tests/test_aero_dist.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pytest
1212

1313
import PyPartMC as ppmc
14+
from PyPartMC import si
1415

1516
from .test_aero_data import AERO_DATA_CTOR_ARG_MINIMAL
1617
from .test_aero_mode import (
@@ -31,6 +32,25 @@
3132
AERO_MODE_CTOR_LOG_NORMAL_COAGULATION,
3233
]
3334

35+
AERO_DIST_CTOR_ARG_AVERAGE = [
36+
{
37+
"test_mode_A": {
38+
"mass_frac": [{"SO4": [1]}],
39+
"diam_type": "geometric",
40+
"mode_type": "mono",
41+
"num_conc": 1e12 / si.m**3,
42+
"diam": 2 * si.um,
43+
},
44+
"test_mode_B": {
45+
"mass_frac": [{"BC": [1]}],
46+
"diam_type": "geometric",
47+
"mode_type": "mono",
48+
"num_conc": 1e12 / si.m**3,
49+
"diam": 0.2 * si.um,
50+
},
51+
}
52+
]
53+
3454

3555
@pytest.fixture(name="sut_minimal")
3656
def sut_minimal_fixture():

tests/test_aero_state.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
import PyPartMC as ppmc
1313

1414
from .test_aero_data import AERO_DATA_CTOR_ARG_FULL, AERO_DATA_CTOR_ARG_MINIMAL
15-
from .test_aero_dist import AERO_DIST_CTOR_ARG_FULL, AERO_DIST_CTOR_ARG_MINIMAL
15+
from .test_aero_dist import (
16+
AERO_DIST_CTOR_ARG_AVERAGE,
17+
AERO_DIST_CTOR_ARG_FULL,
18+
AERO_DIST_CTOR_ARG_MINIMAL,
19+
)
1620
from .test_env_state import ENV_STATE_CTOR_ARG_MINIMAL
1721

1822
AERO_STATE_CTOR_ARG_MINIMAL = 44, "nummass_source"
@@ -42,6 +46,17 @@ def sut_full():
4246
return sut
4347

4448

49+
@pytest.fixture
50+
def sut_average():
51+
aero_data = ppmc.AeroData(AERO_DATA_CTOR_ARG_FULL)
52+
aero_dist = ppmc.AeroDist(aero_data, AERO_DIST_CTOR_ARG_AVERAGE)
53+
sut = ppmc.AeroState(aero_data, *AERO_STATE_CTOR_ARG_MINIMAL)
54+
_ = sut.dist_sample(aero_dist, 1.0, 0.0, True, True)
55+
aero_data = None
56+
gc.collect()
57+
return sut
58+
59+
4560
class TestAeroState:
4661
@staticmethod
4762
def test_ctor():
@@ -260,15 +275,25 @@ def test_mixing_state(sut_minimal): # pylint: disable=redefined-outer-name
260275
assert len(mixing_state) == 3
261276

262277
@staticmethod
263-
def test_bin_average_comp(sut_minimal): # pylint: disable=redefined-outer-name
278+
@pytest.mark.parametrize("n_bin", (1, 123))
279+
def test_bin_average_comp(
280+
sut_average, n_bin
281+
): # pylint: disable=redefined-outer-name
264282
# arrange
265-
bin_grid = ppmc.BinGrid(123, "log", 1e-9, 1e-4)
283+
bin_grid = ppmc.BinGrid(n_bin, "log", 1e-9, 1e-4)
266284

267285
# act
268-
sut_minimal.bin_average_comp(bin_grid)
286+
sut_average.bin_average_comp(bin_grid)
287+
so4_masses = np.array(sut_average.masses(include=["SO4"]))
288+
bc_masses = np.array(sut_average.masses(include=["BC"]))
269289

270290
# assert
271-
# TODO #179
291+
if n_bin == 1:
292+
assert np.all(
293+
np.isclose(so4_masses / bc_masses, so4_masses[0] / bc_masses[0])
294+
)
295+
else:
296+
assert np.logical_xor(so4_masses > 0, bc_masses > 0).all()
272297

273298
@staticmethod
274299
def test_get_particle(sut_minimal): # pylint: disable=redefined-outer-name

0 commit comments

Comments
 (0)