Skip to content

Commit

Permalink
test: wrote the pmv_ppd test using the validation table
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoTartarini committed Oct 16, 2024
1 parent 942374d commit b5a3f9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 109 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Urls(Enum):
WBGT = "ts_wbgt.json"
HEAT_INDEX = "ts_heat_index.json"
NET = "ts_net.json"
PMV_PDD = "ts_pmv_pdd.json"
PMV_PPD = "ts_pmv_ppd.json"
PMV = "ts_pmv.json"
SET = "ts_set.json"
HUMIDEX = "ts_humidex.json"
Expand Down
121 changes: 13 additions & 108 deletions tests/test_pmv_ppd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,81 +8,26 @@
)
from pythermalcomfort.models.pmv_ppd import _pmv_ppd_optimized

# fmt: off
data_test_set_ip = [ # I have commented the lines of code that don't pass the test
{'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 74.9},
{'tdb': 32, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 53.7},
{'tdb': 50, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 62.3},
{'tdb': 59, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 66.5},
{'tdb': 68, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 70.7},
{'tdb': 86, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 79.6},
{'tdb': 104, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 93.8},
{'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 10, 'met': 1, 'clo': 0.5, 'set': 74.0},
{'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 90, 'met': 1, 'clo': 0.5, 'set': 76.8},
{'tdb': 77, 'tr': 77, 'v': 19.7 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 75.2},
{'tdb': 77, 'tr': 77, 'v': 118.1 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 70.4},
{'tdb': 77, 'tr': 77, 'v': 216.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 68.4},
{'tdb': 77, 'tr': 77, 'v': 590.6 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 65.6},
{'tdb': 77, 'tr': 50, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 59.6},
{'tdb': 77, 'tr': 104, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 88.9},
{'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.1, 'set': 69.3},
{'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 1, 'set': 81.0},
{'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 2, 'set': 90.3},
{'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 4, 'set': 99.7},
{'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 0.8, 'clo': 0.5, 'set': 73.9},
{'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 2, 'clo': 0.5, 'set': 78.7},
{'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 4, 'clo': 0.5, 'set': 86.8},
]

data_test_pmv_ip = [ # I have commented the lines of code that don't pass the test
{'tdb': 67.3, 'rh': 86, 'vr': 20 / 60, 'met': 1.1, 'clo': 1, 'pmv': -0.5, 'ppd': 10},
{'tdb': 75.0, 'rh': 66, 'vr': 20 / 60, 'met': 1.1, 'clo': 1, 'pmv': 0.5, 'ppd': 10},
{'tdb': 78.2, 'rh': 15, 'vr': 20 / 60, 'met': 1.1, 'clo': 1, 'pmv': 0.5, 'ppd': 10},
{'tdb': 70.2, 'rh': 20, 'vr': 20 / 60, 'met': 1.1, 'clo': 1, 'pmv': -0.5, 'ppd': 10},
{'tdb': 74.5, 'rh': 67, 'vr': 20 / 60, 'met': 1.1, 'clo': .5, 'pmv': -0.5, 'ppd': 10},
{'tdb': 80.2, 'rh': 56, 'vr': 20 / 60, 'met': 1.1, 'clo': .5, 'pmv': 0.5, 'ppd': 10},
{'tdb': 82.2, 'rh': 13, 'vr': 20 / 60, 'met': 1.1, 'clo': .5, 'pmv': 0.5, 'ppd': 10},
{'tdb': 76.5, 'rh': 16, 'vr': 20 / 60, 'met': 1.1, 'clo': .5, 'pmv': -0.5, 'ppd': 10},
]
# fmt: on

from pythermalcomfort.models import pmv_ppd
from tests.conftest import Urls, retrieve_reference_table, validate_result

class TestPmvPpd:

# Returns a dictionary with 'pmv' and 'ppd' keys
def test_returns_dictionary_with_pmv_and_ppd_keys(self):
# Arrange
tdb = [25]
tr = [23]
vr = [0.5]
rh = [50]
met = [1.2]
clo = [0.5]
def test_pmv_ppd(get_test_url, retrieve_data):
reference_table = retrieve_reference_table(
get_test_url, retrieve_data, Urls.PMV_PPD.name
)
tolerance = reference_table["tolerance"]

# Act
result = pmv_ppd(tdb, tr, vr, rh, met, clo)
for entry in reference_table["data"]:
inputs = entry["inputs"]
outputs = entry["outputs"]
result = pmv_ppd(**inputs)

# Assert
assert isinstance(result, dict)
assert "pmv" in result.keys()
assert "ppd" in result.keys()
validate_result(result, outputs, tolerance)

# Calculates PMV and PPD values for valid input values
def test_calculates_pmv_and_ppd_values_for_valid_input_values(self):
# Arrange
tdb = [25]
tr = [23]
vr = [0.5]
rh = [50]
met = [1.2]
clo = [0.5]

# Act
result = pmv_ppd(tdb, tr, vr, rh, met, clo)

# Assert
assert math.isclose(result["pmv"][0], -0.82)
assert math.isclose(result["ppd"][0], 19)
class TestPmvPpd:

# Raises a ValueError if standard is not ISO or ASHRAE
def test_raises_value_error_if_standard_is_not_iso_or_ashrae(self):
Expand Down Expand Up @@ -115,46 +60,6 @@ def test_returns_nan_for_invalid_input_values(self):
assert math.isnan(result["pmv"][1])
assert math.isnan(result["ppd"][1])

for row in data_test_pmv_ip:
assert (
abs(
round(
pmv_ppd(
row["tdb"],
row["tdb"],
row["vr"],
row["rh"],
row["met"],
row["clo"],
standard="ashrae",
units="ip",
)["pmv"],
1,
)
- row["pmv"]
)
< 0.011
)
assert (
abs(
round(
pmv_ppd(
row["tdb"],
row["tdb"],
row["vr"],
row["rh"],
row["met"],
row["clo"],
standard="ashrae",
units="ip",
)["ppd"],
1,
)
- row["ppd"]
)
< 1
)

assert (
round(pmv_ppd(67.28, 67.28, 0.328084, 86, 1.1, 1, units="ip")["pmv"], 1)
) == -0.5
Expand Down

0 comments on commit b5a3f9b

Please sign in to comment.