Added lighting desciption tests

This commit is contained in:
Khalim Conn-Kowlessar 2023-07-03 15:36:51 +01:00
parent 955d0ea94c
commit c0d693c5ed
3 changed files with 64 additions and 4 deletions

View file

@ -32,4 +32,4 @@ class LightingAttributes:
"low_energy_proportion": proportion
}
return {"low_energy_proportion": 0}
raise NotImplementedError("Not handled this case - investigate me")

View file

@ -25,9 +25,9 @@ test_cases = [
{'original_description': 'Low energy lighting in 51% of fixed outlets', 'low_energy_proportion': 0.51},
{'original_description': 'Low energy lighting in 99% of fixed outlets', 'low_energy_proportion': 0.99},
{'original_description': 'Low energy lighting in 100% of fixed outlets', 'low_energy_proportion': 1.0},
{'original_description': 'Good lighting efficiency', 'low_energy_proportion': 98.16666666666667},
{'original_description': 'Below average lighting efficiency', 'low_energy_proportion': 0.0},
{'original_description': 'Excelent lighting efficiency', 'low_energy_proportion': 0},
{'original_description': 'Good lighting efficiency', 'low_energy_proportion': 0.75},
{'original_description': 'Below average lighting efficiency', 'low_energy_proportion': 0.25},
{'original_description': 'Excellent lighting efficiency', 'low_energy_proportion': 1.0},
{'original_description': 'Low energy lighting in 2% of fixed outlets', 'low_energy_proportion': 0.02},
{'original_description': 'No Low energy lighting', 'low_energy_proportion': 0}
]

View file

@ -0,0 +1,60 @@
import pandas as pd
import pytest
from model_data.tests.test_data.test_lighting_attributes_cases import test_cases
from model_data.epc_attributes.LightingAttributes import LightingAttributes
# An example averages dataset to use in tests. It is a dictionary where the key is a lighting description and the
# value is the expected proportion.
averages = pd.DataFrame(
[
{"lighting-description": "good lighting efficiency", "low-energy-lighting": 0.75},
{"lighting-description": "excellent lighting efficiency", "low-energy-lighting": 1.0},
{"lighting-description": "below average lighting efficiency", "low-energy-lighting": 0.25}
]
)
class TestLightingAttributes:
def test_no_lighting(self):
lighting = LightingAttributes("no low energy lighting", averages)
result = lighting.process()
assert result == {"low_energy_proportion": 0}
def test_all_outlets(self):
lighting = LightingAttributes("Low energy lighting in all fixed outlets", averages)
result = lighting.process()
assert result == {"low_energy_proportion": 1}
def test_good_efficiency(self):
lighting = LightingAttributes("Good lighting efficiency", averages)
result = lighting.process()
assert result == {"low_energy_proportion": 0.75}
def test_excellent_efficiency(self):
lighting = LightingAttributes("Excellent lighting efficiency", averages)
result = lighting.process()
assert result == {"low_energy_proportion": 1}
def test_below_average_efficiency(self):
lighting = LightingAttributes("Below average lighting efficiency", averages)
result = lighting.process()
assert result == {"low_energy_proportion": 0.25}
def test_percentage(self):
lighting = LightingAttributes("Low energy lighting in 50% of fixed outlets", averages)
result = lighting.process()
assert result == {"low_energy_proportion": 0.5}
def test_unknown_description(self):
with pytest.raises(NotImplementedError):
LightingAttributes("This is an unknown description", averages).process()
@pytest.mark.parametrize(
"test_case",
test_cases
)
def test_process_mainheat(self, test_case):
expected_result = test_case.copy()
del expected_result["original_description"]
result = LightingAttributes(test_case['original_description'], averages).process()
assert sorted(result.items()) == sorted(expected_result.items())