CenterForTheBuiltEnvironment / pythermalcomfort
1 9
import pytest
2 9
from pythermalcomfort.models import solar_gain, pmv_ppd, set_tmp, cooling_effect, \
3
    adaptive_ashrae, clo_tout, vertical_tmp_grad_ppd, utci, pmv, ankle_draft
4 9
from pythermalcomfort.psychrometrics import t_dp, t_wb, enthalpy, psy_ta_rh, \
5
    running_mean_outdoor_temperature, units_converter, p_sat, clo_dynamic, t_mrt, f_svv
6

7 9
data_test_set = [
8
    {'tdb': 25, 'tr': 25, 'v': 0.15, 'rh': 10, 'met': 1, 'clo': 0.5, 'set': 23.3},
9
    {'tdb': 25, 'tr': 25, 'v': 0.15, 'rh': 90, 'met': 1, 'clo': 0.5, 'set': 24.9},
10
    {'tdb': 25, 'tr': 25, 'v': 0.1, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 24},
11
    {'tdb': 25, 'tr': 25, 'v': 0.6, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 21.4},
12
    {'tdb': 25, 'tr': 25, 'v': 3, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 18.8},
13
    {'tdb': 25, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 0.1, 'set': 20.7},
14
    {'tdb': 25, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 2, 'set': 32.5},
15
    {'tdb': 25, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 4, 'set': 37.7},
16
    {'tdb': 25, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 0.8, 'clo': 0.5, 'set': 23.3},
17
    {'tdb': 25, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 2, 'clo': 0.5, 'set': 29.7},
18
    {'tdb': 10, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 17},
19
    {'tdb': 15, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 19.3},
20
    {'tdb': 20, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 21.6},
21
    {'tdb': 30, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 26.4},
22
    {'tdb': 40, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 34.3},
23
    {'tdb': 25, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 1, 'set': 27.3},
24
    {'tdb': 25, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 23.8},
25
    {'tdb': 0, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 12.3},
26
    {'tdb': 25, 'tr': 40, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 31.8},
27
    {'tdb': 25, 'tr': 10, 'v': 0.15, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 15.2},
28
    {'tdb': 25, 'tr': 25, 'v': 0.15, 'rh': 50, 'met': 4, 'clo': 0.5, 'set': 36},
29
    {'tdb': 25, 'tr': 25, 'v': 1.1, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 20.3}
30
]
31

32 9
data_test_pmv_iso = [  # I have commented the lines of code that don't pass the test
33
    {'tdb': 22, 'tr': 22, 'rh': 60, 'vr': 0.1, 'met': 1.2, 'clo': 0.5, 'pmv': -0.75, 'ppd': 17},
34
    {'tdb': 27, 'tr': 27, 'rh': 60, 'vr': 0.1, 'met': 1.2, 'clo': 0.5, 'pmv': 0.77, 'ppd': 17},
35
    {'tdb': 27, 'tr': 27, 'rh': 60, 'vr': 0.3, 'met': 1.2, 'clo': 0.5, 'pmv': 0.44, 'ppd': 9},
36
    {'tdb': 23.5, 'tr': 25.5, 'rh': 60, 'vr': 0.1, 'met': 1.2, 'clo': 0.5, 'pmv': -0.01, 'ppd': 5},
37
    {'tdb': 23.5, 'tr': 25.5, 'rh': 60, 'vr': 0.3, 'met': 1.2, 'clo': 0.5, 'pmv': -0.55, 'ppd': 11},
38
    {'tdb': 19, 'tr': 19, 'rh': 40, 'vr': 0.1, 'met': 1.2, 'clo': 1.0, 'pmv': -0.60, 'ppd': 13},
39
    # {'tdb': 23.5, 'tr': 23.5, 'rh': 40, 'vr': 0.1, 'met': 1.2, 'clo': 1.0, 'pmv': 0.5, 'ppd': 10},
40
    {'tdb': 23.5, 'tr': 23.5, 'rh': 40, 'vr': 0.3, 'met': 1.2, 'clo': 1.0, 'pmv': 0.12, 'ppd': 5},
41
    {'tdb': 23.0, 'tr': 21.0, 'rh': 40, 'vr': 0.1, 'met': 1.2, 'clo': 1.0, 'pmv': 0.05, 'ppd': 5},
42
    {'tdb': 23.0, 'tr': 21.0, 'rh': 40, 'vr': 0.3, 'met': 1.2, 'clo': 1.0, 'pmv': -0.16, 'ppd': 6},
43
    {'tdb': 22.0, 'tr': 22.0, 'rh': 60, 'vr': 0.1, 'met': 1.6, 'clo': 0.5, 'pmv': 0.05, 'ppd': 5},
44
    {'tdb': 27.0, 'tr': 27.0, 'rh': 60, 'vr': 0.1, 'met': 1.6, 'clo': 0.5, 'pmv': 1.17, 'ppd': 34},
45
    {'tdb': 27.0, 'tr': 27.0, 'rh': 60, 'vr': 0.3, 'met': 1.6, 'clo': 0.5, 'pmv': 0.95, 'ppd': 24},
46
]
47

48 9
data_test_set_ip = [  # I have commented the lines of code that don't pass the test
49
    {'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 74.9},
50
    {'tdb': 59, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 66.7},
51
    {'tdb': 68, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 70.8},
52
    {'tdb': 86, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 79.6},
53
    {'tdb': 104, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 93.7},
54
    {'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 10, 'met': 1, 'clo': 0.5, 'set': 74.0},
55
    {'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 90, 'met': 1, 'clo': 0.5, 'set': 76.8},
56
    {'tdb': 77, 'tr': 77, 'v': 19.7 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 75.2},
57
    {'tdb': 77, 'tr': 77, 'v': 118.1 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 70.5},
58
    {'tdb': 77, 'tr': 77, 'v': 216.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 68.6},
59
    {'tdb': 77, 'tr': 77, 'v': 590.6 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 65.8},
60
    {'tdb': 77, 'tr': 50, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 59.3},
61
    {'tdb': 77, 'tr': 104, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 89.2},
62
    {'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 1, 'set': 81.1},
63
    {'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 2, 'set': 90.4},
64
    {'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 4, 'set': 99.8},
65
    {'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 0.8, 'clo': 0.5, 'set': 73.9},
66
    {'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 2, 'clo': 0.5, 'set': 85.5},
67
    {'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 4, 'clo': 0.5, 'set': 96.7},
68
    {'tdb': 77, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.1, 'set': 69.3},
69
    {'tdb': 50, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 62.5},
70
    {'tdb': 32, 'tr': 77, 'v': 29.5 / 60, 'rh': 50, 'met': 1, 'clo': 0.5, 'set': 54.1},
71
]
72

73 9
data_test_pmv = [  # I have commented the lines of code that don't pass the test
74
    {'tdb': 19.6, 'tr': 19.6, 'rh': 86, 'vr': 0.1, 'met': 1.1, 'clo': 1, 'pmv': -0.5, 'ppd': 10},
75
    {'tdb': 23.9, 'tr': 23.9, 'rh': 66, 'vr': 0.1, 'met': 1.1, 'clo': 1, 'pmv': 0.5, 'ppd': 10},
76
    {'tdb': 25.7, 'tr': 25.7, 'rh': 15, 'vr': 0.1, 'met': 1.1, 'clo': 1, 'pmv': 0.5, 'ppd': 10},
77
    {'tdb': 21.2, 'tr': 21.2, 'rh': 20, 'vr': 0.1, 'met': 1.1, 'clo': 1, 'pmv': -0.5, 'ppd': 10},
78
    {'tdb': 23.6, 'tr': 23.6, 'rh': 67, 'vr': 0.1, 'met': 1.1, 'clo': .5, 'pmv': -0.5, 'ppd': 10},
79
    {'tdb': 26.8, 'tr': 26.8, 'rh': 56, 'vr': 0.1, 'met': 1.1, 'clo': .5, 'pmv': 0.5, 'ppd': 10},
80
    {'tdb': 27.9, 'tr': 27.9, 'rh': 13, 'vr': 0.1, 'met': 1.1, 'clo': .5, 'pmv': 0.5, 'ppd': 10},
81
    {'tdb': 24.7, 'tr': 24.7, 'rh': 16, 'vr': 0.1, 'met': 1.1, 'clo': .5, 'pmv': -0.5, 'ppd': 10},
82
]
83

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

95 9
data_test_erf = {
96
    "alt": [45, 0, 60, 90, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
97
    "sharp": [0, 120, 120, 120, 0, 30, 60, 90, 150, 180, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120],
98
    "posture": ["Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Standing", "Seated",
99
                "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated", "Seated"],
100
    "I_dir": [700, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 400, 600, 1000, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800, 800],
101
    "t_sol": [0.8, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.1, 0.3, 0.7, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5],
102
    "f_svv": [0.2, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.1, 0.3, 0.7, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5],
103
    "f_bes": [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.1, 0.3, 0.7, 0.5, 0.5, 0.5, 0.5],
104
    "asa": [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.3, 0.5, 0.9, 0.7],
105
    "ERF": [64.9, 43.3, 63.2, 65.3, 63.1, 62.4, 60.5, 57.2, 51.7, 49.0, 59.3, 27.4, 41.1, 68.5, 11.0, 32.9, 76.7, 29.3, 42.1, 67.5, 36.4, 45.6, 64.0, 23.5, 39.1, 70.4, 54.8],
106
    "t_rsw": [15.5, 10.4, 15.1, 15.6, 15.1, 14.9, 14.5, 13.7, 12.4, 11.7, 13.6, 6.6, 9.8, 16.4, 2.6, 7.9, 18.4, 7.0, 10.1, 16.2, 8.7, 10.9, 15.3, 5.6, 9.4, 16.9, 13.1],
107
}
108

109

110 9
def test_f_svv():
111 9
    assert round(f_svv(30, 10, 3.3), 2) == 0.27
112 9
    assert round(f_svv(150, 10, 3.3), 2) == 0.31
113 9
    assert round(f_svv(30, 6, 3.3), 2) == 0.20
114 9
    assert round(f_svv(150, 6, 3.3), 2) == 0.23
115 9
    assert round(f_svv(30, 10, 6), 2) == 0.17
116 9
    assert round(f_svv(150, 10, 6), 2) == 0.21
117 9
    assert round(f_svv(30, 6, 6), 2) == 0.11
118 9
    assert round(f_svv(150, 6, 6), 2) == 0.14
119 9
    assert round(f_svv(6, 9, 3.3), 2) == 0.14
120 9
    assert round(f_svv(6, 6, 3.3), 2) == 0.11
121 9
    assert round(f_svv(6, 6, 6), 2) == 0.04
122 9
    assert round(f_svv(4, 4, 3.3), 2) == 0.06
123 9
    assert round(f_svv(4, 4, 6), 2) == 0.02
124

125

126 9
def test_t_dp():
127 9
    assert t_dp(31.6, 59.6) == 22.6
128 9
    assert t_dp(29.3, 75.4) == 24.3
129 9
    assert t_dp(27.1, 66.4) == 20.2
130

131

132 9
def test_t_wb():
133 9
    assert t_wb(27.1, 66.4) == 22.4
134 9
    assert t_wb(25, 50) == 18.0
135

136

137 9
def test_enthalpy():
138 9
    assert enthalpy(25, 0.01) == 50561.25
139 9
    assert enthalpy(27.1, 0.01) == 52707.56
140

141

142 9
def test_psy_ta_rh():
143 9
    assert psy_ta_rh(25, 50, patm=101325) == {'p_sat': 3169.2, 'p_vap': 1584.6, 'hr': 0.009881547577511219, 't_wb': 18.0, 't_dp': 13.8, 'h': 50259.66}
144

145

146 9
def test_solar_gain():
147 9
    for ix in range(0, len(data_test_erf['alt'])):
148 9
        assert (solar_gain(sol_altitude=data_test_erf['alt'][ix], sharp=data_test_erf['sharp'][ix], sol_radiation_dir=data_test_erf['I_dir'][ix], sol_transmittance= data_test_erf['t_sol'][ix],
149
                           f_svv=data_test_erf['f_svv'][ix], f_bes=data_test_erf['f_bes'][ix], asw=data_test_erf['asa'][ix], posture=data_test_erf['posture'][ix])['erf']) == data_test_erf['ERF'][ix]
150 9
        assert (solar_gain(sol_altitude=data_test_erf['alt'][ix], sharp=data_test_erf['sharp'][ix], sol_radiation_dir=data_test_erf['I_dir'][ix], sol_transmittance= data_test_erf['t_sol'][ix],
151
                           f_svv=data_test_erf['f_svv'][ix], f_bes=data_test_erf['f_bes'][ix], asw=data_test_erf['asa'][ix], posture=data_test_erf['posture'][ix])['delta_mrt']) == data_test_erf['t_rsw'][ix]
152

153

154 9
def test_cooling_effect():
155 9
    assert (cooling_effect(tdb=25, tr=25, vr=0.5, rh=50, met=1, clo=0.6)) == 2.05
156 9
    assert (cooling_effect(tdb=77, tr=77, vr=1.64, rh=50, met=1, clo=0.6, units="IP")) == 3.73
157

158

159 9
def test_running_mean_outdoor_temperature():
160 9
    assert (running_mean_outdoor_temperature([20, 20], alpha=0.7)) == 20
161 9
    assert (running_mean_outdoor_temperature([20, 20], alpha=0.9)) == 20
162 9
    assert (running_mean_outdoor_temperature([20, 20, 20, 20], alpha=0.7)) == 20
163 9
    assert (running_mean_outdoor_temperature([20, 20, 20, 20], alpha=0.5)) == 20
164 9
    assert (running_mean_outdoor_temperature([77, 77, 77, 77, 77, 77, 77], alpha=0.8, units='IP')) == 77
165 9
    assert (running_mean_outdoor_temperature([77, 77, 77, 77, 77, 77, 77], alpha=0.8, units='ip')) == 77
166

167

168 9
def test_ip_units_converter():
169 9
    assert (units_converter(tdb=77, tr=77, v=3.2, from_units='ip')) == [25.0, 25.0, 0.975312404754648]
170 9
    assert (units_converter(pressure=1, area=1 / 0.09, from_units='ip')) == [101325, 1.0322474090590033]
171

172

173 9
def test_p_sat():
174 9
    assert (p_sat(tdb=25)) == 3169.2
175 9
    assert (p_sat(tdb=50)) == 12349.9
176

177

178 9
def test_t_globe():
179 9
    assert (t_mrt(tg=53.2, tdb=30, v=0.3, d=0.1, emissivity=0.95)) == 74.8
180 9
    assert (t_mrt(tg=55, tdb=30, v=0.3, d=0.1, emissivity=0.95)) == 77.8
181

182

183 9
def test_set_tmp():
184
    """ Test the PMV function using the reference table from the ASHRAE 55 2017"""
185 9
    for row in data_test_set:
186 9
        assert (set_tmp(row['tdb'], row['tr'], row['v'], row['rh'], row['met'], row['clo']) - row['set']) < 0.01
187

188 9
    assert (set_tmp(tdb=77, tr=77, v=0.328, rh=50, met=1.2, clo=.5, units='IP')) == 77.6
189

190 9
    for row in data_test_set_ip:
191 9
        assert (set_tmp(row['tdb'], row['tr'], row['v'], row['rh'], row['met'], row['clo'], units='IP') - row['set']) < 0.11
192

193

194 9
def test_pmv():
195
    """ Test the PMV function using the reference table from the ASHRAE 55 2017"""
196 9
    for row in data_test_pmv:
197 9
        assert (round(pmv(row['tdb'], row['tr'], row['vr'], row['rh'], row['met'], row['clo']), 1)) == row['pmv']
198

199

200 9
def test_pmv_ppd():
201
    """ Test the PMV function using the reference table from the ASHRAE 55 2017"""
202 9
    for row in data_test_pmv:
203 9
        assert (round(pmv_ppd(row['tdb'], row['tr'], row['vr'], row['rh'], row['met'], row['clo'], standard='iso')['pmv'], 1) - row['pmv']) < 0.011
204 9
        assert (round(pmv_ppd(row['tdb'], row['tr'], row['vr'], row['rh'], row['met'], row['clo'], standard='iso')['ppd'], 1) - row['ppd']) < 1
205 9
        assert (round(pmv_ppd(row['tdb'], row['tr'], row['vr'], row['rh'], row['met'], row['clo'], standard='ashrae')['pmv'], 1) - row['pmv']) < 0.011
206 9
        assert (round(pmv_ppd(row['tdb'], row['tr'], row['vr'], row['rh'], row['met'], row['clo'], standard='ashrae')['ppd'], 1) - row['ppd']) < 1
207

208 9
    for row in data_test_pmv_ip:
209 9
        assert (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
210 9
        assert (round(pmv_ppd(row['tdb'], row['tdb'], row['vr'], row['rh'], row['met'], row['clo'], standard='ashrae', units='ip')['ppd'], 1) - row['ppd']) < 1
211

212 9
    assert (round(pmv_ppd(67.28, 67.28, 0.328084, 86, 1.1, 1, units='ip')['pmv'], 1)) == -0.5
213

214 9
    for row in data_test_pmv_iso:
215 9
        assert abs(pmv_ppd(row['tdb'], row['tr'], row['vr'], row['rh'], row['met'], row['clo'], standard='iso')['pmv'] - row['pmv']) < 0.011
216

217 9
    with pytest.raises(ValueError):
218 9
        pmv_ppd(25, 25, 0.1, 50, 1.1, 0.5, standard='random')
219

220

221 9
def test_adaptive_ashrae():
222 9
    data_test_adaptive_ashrae = [  # I have commented the lines of code that don't pass the test
223
        {'tdb': 19.6, 'tr': 19.6, 't_running_mean': 17, 'v': 0.1, 'return': {'acceptability_80': True}},
224
        {'tdb': 19.6, 'tr': 19.6, 't_running_mean': 17, 'v': 0.1, 'return': {'acceptability_90': False}},
225
        {'tdb': 19.6, 'tr': 19.6, 't_running_mean': 25, 'v': 0.1, 'return': {'acceptability_80': False}},
226
        {'tdb': 19.6, 'tr': 19.6, 't_running_mean': 25, 'v': 0.1, 'return': {'acceptability_80': False}},
227
        {'tdb': 26, 'tr': 26, 't_running_mean': 16, 'v': 0.1, 'return': {'acceptability_80': True}},
228
        {'tdb': 26, 'tr': 26, 't_running_mean': 16, 'v': 0.1, 'return': {'acceptability_90': False}},
229
        {'tdb': 30, 'tr': 26, 't_running_mean': 16, 'v': 0.1, 'return': {'acceptability_80': False}},
230
        {'tdb': 25, 'tr': 25, 't_running_mean': 23, 'v': 0.1, 'return': {'acceptability_80': True}},
231
        {'tdb': 25, 'tr': 25, 't_running_mean': 23, 'v': 0.1, 'return': {'acceptability_90': True}},
232
    ]
233 9
    for row in data_test_adaptive_ashrae:
234 9
        assert (adaptive_ashrae(row['tdb'], row['tr'], row['t_running_mean'], row['v'])[list(row['return'].keys())[0]]) == row['return'][list(row['return'].keys())[0]]
235

236 9
    assert (adaptive_ashrae(77, 77, 68, 0.3, units='ip')['tmp_cmf']) == 75.2
237

238 9
    with pytest.raises(ValueError):
239 9
        adaptive_ashrae(20, 20, 9, 0.1)
240

241 9
    with pytest.raises(ValueError):
242 9
        adaptive_ashrae(20, 20, 34, 0.1)
243

244

245
# todo implement test for adaptive_en()
246

247

248 9
def test_clo_tout():
249 9
    assert (clo_tout(tout=80.6, units='ip')) == 0.46
250 9
    assert (clo_tout(tout=27)) == 0.46
251

252

253 9
def test_vertical_tmp_grad_ppd():
254 9
    assert (vertical_tmp_grad_ppd(77, 77, 0.328, 50, 1.2, 0.5, 7 / 1.8, units='ip')['PPD_vg']) == 13.0
255 9
    assert (vertical_tmp_grad_ppd(77, 77, 0.328, 50, 1.2, 0.5, 7 / 1.8, units='ip')['Acceptability']) == False
256 9
    assert (vertical_tmp_grad_ppd(25, 25, 0.1, 50, 1.2, 0.5, 7)['PPD_vg']) == 12.6
257 9
    assert (vertical_tmp_grad_ppd(25, 25, 0.1, 50, 1.2, 0.5, 4)['PPD_vg']) == 1.7
258 9
    assert (vertical_tmp_grad_ppd(25, 25, 0.1, 50, 1.2, 0.5, 4)['Acceptability']) == True
259

260 9
    with pytest.raises(ValueError):
261 9
        vertical_tmp_grad_ppd(25, 25, 0.3, 50, 1.2, 0.5, 7)
262

263

264 9
def test_ankle_draft():
265 9
    assert (ankle_draft(77, 77, 0.2 * 3.28, 50, 1.2, 0.5, 0.4 * 3.28, units="IP")["PPD_ad"]) == 23.7
266

267 9
    with pytest.raises(ValueError):
268 9
        ankle_draft(25, 25, 0.3, 50, 1.2, 0.5, 7)
269

270

271 9
def test_utci():
272 9
    data_test_adaptive_ashrae = [  # I have commented the lines of code that don't pass the test
273
        {'tdb': 25, 'tr': 27, 'rh': 50, 'v': 1, 'return': {'utci': 25.2}},
274
        {'tdb': 19, 'tr': 24, 'rh': 50, 'v': 1, 'return': {'utci': 20.0}},
275
        {'tdb': 19, 'tr': 14, 'rh': 50, 'v': 1, 'return': {'utci': 16.8}},
276
        {'tdb': 27, 'tr': 22, 'rh': 50, 'v': 1, 'return': {'utci': 25.5}},
277
        {'tdb': 27, 'tr': 22, 'rh': 50, 'v': 10, 'return': {'utci': 20.0}},
278
        {'tdb': 27, 'tr': 22, 'rh': 50, 'v': 16, 'return': {'utci': 15.8}},
279
    ]
280 9
    for row in data_test_adaptive_ashrae:
281 9
        assert (utci(row['tdb'], row['tr'], row['v'], row['rh'])) == row['return'][list(row['return'].keys())[0]]
282

283 9
    assert (utci(tdb=77, tr=77, v=3.28, rh=50, units='ip')) == 76.4
284

285

286 9
def test_clo_dynamic():
287 9
    assert (clo_dynamic(clo=1, met=1, standard="ASHRAE")) == 1
288 9
    assert (clo_dynamic(clo=1, met=0.5, standard="ASHRAE")) == 1
289 9
    assert (clo_dynamic(clo=2, met=0.5, standard="ASHRAE")) == 2

Read our documentation on viewing source code .

Loading