Finish A3 P4 Q2 Q3

This commit is contained in:
MstrPikachu
2021-10-30 21:22:00 -04:00
parent 36cbf547d0
commit 58cb6190b6
2 changed files with 50 additions and 24 deletions
+46 -21
View File
@@ -28,11 +28,11 @@ class TestCalculateMr:
def test_equation_3a_branch(self) -> None:
"""Test the branch calculate_mr that contains Equation 3a."""
assert 123.82 == pytest.approx(ffwi.calculate_mr(2.4, 80))
assert 123.823 == pytest.approx(ffwi.calculate_mr(2.4, 80))
def test_equation_3b_branch(self) -> None:
"""Test the branch calculate_mr that contains Equation 3b."""
assert 182.80 == pytest.approx(ffwi.calculate_mr(2.4, 155))
assert 182.803 == pytest.approx(ffwi.calculate_mr(2.4, 155))
class TestCalculateM:
@@ -40,19 +40,31 @@ class TestCalculateM:
def test_no_mutation_mo_equals_ed(self) -> None:
"""Test that calculate_m does not mutate the WeatherMetrics argument when mo == ed."""
# TODO: Complete this unit test and remove this TODO
wm_old = WeatherMetrics(1, 2, 3.0, 4.0, 5.0, 6.0)
wm_new = WeatherMetrics(1, 2, 3.0, 4.0, 5.0, 6.0)
ffwi.calculate_m(wm_new, 0.5, 0.5)
assert wm_old == wm_new
def test_no_mutation_mo_leq_ew(self) -> None:
"""Test that calculate_m does not mutate the WeatherMetrics argument when mo <= ew."""
# TODO: Complete this unit test and remove this TODO
wm_old = WeatherMetrics(1, 2, 3.0, 4.0, 5.0, 6.0)
wm_new = WeatherMetrics(1, 2, 3.0, 4.0, 5.0, 6.0)
ffwi.calculate_m(wm_new, 0.5, 0.1)
assert wm_old == wm_new
def test_no_mutation_mo_greater_than_ew(self) -> None:
"""Test that calculate_m does not mutate the WeatherMetrics argument when mo > ew."""
# TODO: Complete this unit test and remove this TODO
wm_old = WeatherMetrics(1, 2, 3.0, 4.0, 5.0, 6.0)
wm_new = WeatherMetrics(1, 2, 3.0, 4.0, 5.0, 6.0)
ffwi.calculate_m(wm_new, 5.0, 3.0)
assert wm_old == wm_new
def test_no_mutation_mo_greater_than_ed(self) -> None:
"""Test that calculate_m does not mutate the WeatherMetrics argument when mo > ed."""
# TODO: Complete this unit test and remove this TODO
wm_old = WeatherMetrics(1, 2, 3.0, 4.0, 5.0, 6.0)
wm_new = WeatherMetrics(1, 2, 3.0, 4.0, 5.0, 6.0)
ffwi.calculate_m(wm_new, 0.01, 0.1)
assert wm_old == wm_new
@pytest.fixture
@@ -69,9 +81,9 @@ def test_ffmc_against_ground_truth(sample_data) -> None:
"""Test the correctness of calculate_ffmc, calculate_dmc, calculate_dc, calculate_isi,
calculate_bui, and calculate_fwi based on sample_data.
Ensure that, for every WeatherMetric element in sample_data[0] passed to each of the calculate_
Ensure that, for every WeatherMetric element in inputs passed to each of the calculate_
functions mentioned above, the return value, rounded to the nearest decimal, matches the
corresponding value from the FfwiOutput element in sample_data[1].
corresponding value from the FfwiOutput element in outputs.
Hints:
- You will need to use the built-in function round.
@@ -82,7 +94,20 @@ def test_ffmc_against_ground_truth(sample_data) -> None:
dc = ffwi.INITIAL_DC
inputs, outputs = sample_data
# TODO: Complete this test and remove this TODO.
for i in range(len(sample_data)):
ffmc = ffwi.calculate_ffmc(inputs[i], ffmc)
dmc = ffwi.calculate_dmc(inputs[i], dmc)
dc = ffwi.calculate_dc(inputs[i], dc)
isi = ffwi.calculate_isi(inputs[i], ffmc)
bui = ffwi.calculate_bui(dmc, dc)
fwi = ffwi.calculate_fwi(isi, bui)
assert round(ffmc, 1) == pytest.approx(outputs[i].ffmc)
assert round(dmc, 1) == pytest.approx(outputs[i].dmc)
assert round(dc, 1) == pytest.approx(outputs[i].dc)
assert round(isi, 1)== pytest.approx(outputs[i].isi)
assert round(bui, 1) == pytest.approx(outputs[i].bui)
assert round(fwi, 1) == pytest.approx(outputs[i].fwi)
if __name__ == '__main__':
@@ -91,15 +116,15 @@ if __name__ == '__main__':
# When you are ready to check your work with python_ta, uncomment the following lines.
# (Delete the "#" and space before each line.)
# IMPORTANT: keep this code indented inside the "if __name__ == '__main__'" block
# import python_ta
# import python_ta.contracts
# python_ta.contracts.DEBUG_CONTRACTS = False
# python_ta.contracts.check_all_contracts()
# python_ta.check_all(config={
# 'allowed-io': ['load_data'],
# 'extra-imports': ['a3_ffwi_system', 'a3_part4', 'pytest'],
# 'max-line-length': 100,
# 'max-args': 6,
# 'max-locals': 25,
# 'disable': ['R1705', 'R0201', 'C0103', 'W0621', 'E9970'],
# })
import python_ta
import python_ta.contracts
python_ta.contracts.DEBUG_CONTRACTS = False
python_ta.contracts.check_all_contracts()
python_ta.check_all(config={
'allowed-io': ['load_data'],
'extra-imports': ['a3_ffwi_system', 'a3_part4', 'pytest'],
'max-line-length': 100,
'max-args': 6,
'max-locals': 25,
'disable': ['R1705', 'R0201', 'C0103', 'W0621', 'E9970'],
})