From 4daf972030958c9f0a41123b1a704f44900674ce Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Fri, 22 Sep 2023 11:03:01 +0100 Subject: [PATCH] added unit tests for roof uvalues --- .../generate_rdsap_change.py | 2 +- .../tests/test_recommendation_utils.py | 72 +++++++++---------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/model_data/simulation_system/generate_rdsap_change.py b/model_data/simulation_system/generate_rdsap_change.py index b986ce50..3797024e 100644 --- a/model_data/simulation_system/generate_rdsap_change.py +++ b/model_data/simulation_system/generate_rdsap_change.py @@ -558,7 +558,7 @@ def app(): save_dataframe_to_s3_parquet( df=output, bucket_name="retrofit-data-dev", - file_key="sap_change_model/dataset_new.parquet", + file_key="sap_change_model/dataset_new_not_diff.parquet", ) diff --git a/recommendations/tests/test_recommendation_utils.py b/recommendations/tests/test_recommendation_utils.py index f6d4905a..10ceccd0 100644 --- a/recommendations/tests/test_recommendation_utils.py +++ b/recommendations/tests/test_recommendation_utils.py @@ -78,7 +78,7 @@ class TestRecommendationUtils: def test_get_roof_u_value(self): # Test case 1: Insulation thickness is known and is_loft is True - description_dict = { + inputs = { 'insulation_thickness': '50', 'is_loft': True, 'is_roof_room': False, @@ -89,10 +89,10 @@ class TestRecommendationUtils: 'is_at_rafters': False, } for age_band in ["A", "B", "C", "D"]: - assert recommendation_utils.get_roof_u_value(description_dict, age_band) == 0.68 + assert recommendation_utils.get_roof_u_value(**{**inputs, "age_band": age_band}) == 0.68 def test_get_roof_u_value_case_2(self): - description_dict = { + inputs = { 'original_description': 'Pitched, 400+ mm insulation at joists', 'clean_description': 'Pitched, 400+ mm insulation at joists', 'thermal_transmittance': None, @@ -106,15 +106,15 @@ class TestRecommendationUtils: 'is_assumed': False, 'has_dwelling_above': False, 'is_valid': True, - 'insulation_thickness': '400+' + 'insulation_thickness': '400+', + 'age_band': "J" } - age_band = "J" - u_value = recommendation_utils.get_roof_u_value(description_dict, age_band) + u_value = recommendation_utils.get_roof_u_value(**inputs) assert u_value == 0.16, f"Expected 0.16, but got {u_value}" def test_get_roof_u_value_case_3(self): - description_dict = { + inputs = { 'original_description': 'Room-in-roof, 200 mm insulation at rafters', 'clean_description': 'Room-in-roof, 200 mm insulation at rafters', 'thermal_transmittance': None, @@ -128,15 +128,15 @@ class TestRecommendationUtils: 'is_assumed': False, 'has_dwelling_above': False, 'is_valid': True, - 'insulation_thickness': '200' + 'insulation_thickness': '200', + 'age_band': "J" } - age_band = "J" - u_value = recommendation_utils.get_roof_u_value(description_dict, age_band) + u_value = recommendation_utils.get_roof_u_value(**inputs) assert u_value == 0.21, f"Expected 0.21, but got {u_value}" def test_get_roof_u_value_case_4(self): - description_dict = { + inputs = { 'original_description': 'Pitched, below average insulation', 'clean_description': 'Pitched, below average insulation', 'thermal_transmittance': None, @@ -150,16 +150,16 @@ class TestRecommendationUtils: 'is_assumed': False, 'has_dwelling_above': False, 'is_valid': True, - 'insulation_thickness': 'below average' + 'insulation_thickness': 'below average', + 'age_band': "E" } - age_band = "E" - u_value = recommendation_utils.get_roof_u_value(description_dict, age_band) + u_value = recommendation_utils.get_roof_u_value(**inputs) assert u_value == 1.5, f"Expected 1.5, but got {u_value}" - def test_get_roof_u_value_case_5(): + def test_get_roof_u_value_case_5(self): # Test case where insulation thickness is exactly specified - description_dict = { + inputs = { 'original_description': 'Pitched, 100mm insulation', 'clean_description': 'Pitched, 100mm insulation', 'thermal_transmittance': None, @@ -173,16 +173,16 @@ class TestRecommendationUtils: 'is_assumed': False, 'has_dwelling_above': False, 'is_valid': True, - 'insulation_thickness': '100' + 'insulation_thickness': '100', + 'age_band': "G" } - age_band = "G" - u_value = get_roof_u_value(description_dict, age_band, table_s9, table_s10) + u_value = recommendation_utils.get_roof_u_value(**inputs) assert u_value == 0.40, f"Expected 0.40, but got {u_value}" - def test_get_roof_u_value_case_6(): + def test_get_roof_u_value_case_6(self): # Test case for a thatched roof - description_dict = { + inputs = { 'original_description': 'Thatched, 75mm insulation', 'clean_description': 'Thatched, 75mm insulation', 'thermal_transmittance': None, @@ -196,16 +196,16 @@ class TestRecommendationUtils: 'is_assumed': False, 'has_dwelling_above': False, 'is_valid': True, - 'insulation_thickness': '75' + 'insulation_thickness': '75', + 'age_band': "H" } - age_band = "H" - u_value = get_roof_u_value(description_dict, age_band, table_s9, table_s10) - assert u_value == 0.22, f"Expected 0.22, but got {u_value}" + u_value = recommendation_utils.get_roof_u_value(**inputs) + assert u_value == 0.35, f"Expected 0.35, but got {u_value}" - def test_get_roof_u_value_case_7(): + def test_get_roof_u_value_case_7(self): # Test case where the roof has a room in it - description_dict = { + inputs = { 'original_description': 'Pitched, room-in-roof, 100mm insulation', 'clean_description': 'Pitched, room-in-roof, 100mm insulation', 'thermal_transmittance': None, @@ -219,16 +219,16 @@ class TestRecommendationUtils: 'is_assumed': False, 'has_dwelling_above': False, 'is_valid': True, - 'insulation_thickness': '100' + 'insulation_thickness': '100', + 'age_band': "J" } - age_band = "J" - u_value = get_roof_u_value(description_dict, age_band, table_s9, table_s10) - assert u_value == 0.30, f"Expected 0.30, but got {u_value}" + u_value = recommendation_utils.get_roof_u_value(**inputs) + assert u_value == 0.40, f"Expected 0.40, but got {u_value}" - def test_get_roof_u_value_case_8(): + def test_get_roof_u_value_case_8(self): # Test case where there is a dwelling above the roof, U-value should be 0 - description_dict = { + inputs = { 'original_description': 'Pitched, 100mm insulation', 'clean_description': 'Pitched, 100mm insulation', 'thermal_transmittance': None, @@ -242,9 +242,9 @@ class TestRecommendationUtils: 'is_assumed': False, 'has_dwelling_above': True, 'is_valid': True, - 'insulation_thickness': '100' + 'insulation_thickness': '100', + 'age_band': "J" } - age_band = "J" - u_value = get_roof_u_value(description_dict, age_band, table_s9, table_s10) + u_value = recommendation_utils.get_roof_u_value(**inputs) assert u_value == 0.0, f"Expected 0.0, but got {u_value}"