| | """ |
| | Integration test script for HVAC Load Calculator. |
| | This script tests the integration of all components of the HVAC Load Calculator. |
| | """ |
| |
|
| | import os |
| | import sys |
| | import json |
| | import unittest |
| | from pathlib import Path |
| |
|
| | |
| | sys.path.append(str(Path(__file__).parent.parent)) |
| |
|
| | |
| | from models.building import Building, CoolingLoadResult |
| | from controllers.enhanced_cooling_load_calculator import calculate_cooling_load |
| | from controllers.monthly_breakdown import calculate_monthly_breakdown, generate_monthly_report |
| | from controllers.building_manager import BuildingManager |
| | from utils.data_io import export_building_to_json, import_building_from_json |
| | from utils.data_io import export_result_to_json, import_result_from_json |
| | from utils.data_io import export_monthly_breakdown_to_csv |
| | from utils.data_io import create_project_archive |
| |
|
| | class TestIntegration(unittest.TestCase): |
| | """Integration test cases for HVAC Load Calculator.""" |
| | |
| | def setUp(self): |
| | """Set up test fixtures.""" |
| | |
| | self.building1 = self._create_test_building("Test Building 1", "New York", 100) |
| | self.building2 = self._create_test_building("Test Building 2", "Chicago", 150) |
| | self.building3 = self._create_test_building("Test Building 3", "Los Angeles", 200) |
| | |
| | |
| | self.building_manager = BuildingManager() |
| | |
| | |
| | os.makedirs("test_output", exist_ok=True) |
| | |
| | def tearDown(self): |
| | """Tear down test fixtures.""" |
| | |
| | for file in os.listdir("test_output"): |
| | os.remove(os.path.join("test_output", file)) |
| | |
| | |
| | os.rmdir("test_output") |
| | |
| | def _create_test_building(self, name, city, area): |
| | """Create a test building.""" |
| | building = Building() |
| | building.settings.name = name |
| | building.settings.floor_area = area |
| | building.settings.ceiling_height = 3 |
| | building.settings.indoor_temp = 24 |
| | building.settings.indoor_humidity = 50 |
| | |
| | building.location.city = city |
| | building.location.latitude = 40.7128 |
| | building.location.longitude = -74.0060 |
| | |
| | |
| | building.add_wall("North", 10, 3, 0.5, "Medium") |
| | building.add_wall("South", 10, 3, 0.5, "Medium") |
| | building.add_wall("East", 10, 3, 0.5, "Medium") |
| | building.add_wall("West", 10, 3, 0.5, "Medium") |
| | |
| | |
| | building.roof.area = area |
| | building.roof.u_value = 0.3 |
| | building.roof.construction_type = "Medium" |
| | |
| | |
| | building.add_glass("North", 2, 1.5, 0.4, 0.8, "Single") |
| | building.add_glass("South", 2, 1.5, 0.4, 0.8, "Single") |
| | |
| | |
| | building.people.count = 5 |
| | building.people.activity = "Office Work" |
| | |
| | |
| | building.lighting.power = 500 |
| | building.lighting.type = "LED" |
| | |
| | |
| | building.equipment.power = 1000 |
| | building.equipment.type = "General" |
| | |
| | return building |
| | |
| | def test_building_manager(self): |
| | """Test building manager functionality.""" |
| | |
| | self.assertTrue(self.building_manager.add_building(self.building1)) |
| | self.assertTrue(self.building_manager.add_building(self.building2)) |
| | self.assertTrue(self.building_manager.add_building(self.building3)) |
| | |
| | |
| | buildings = self.building_manager.get_buildings() |
| | self.assertEqual(len(buildings), 3) |
| | self.assertIn("Test Building 1", buildings) |
| | self.assertIn("Test Building 2", buildings) |
| | self.assertIn("Test Building 3", buildings) |
| | |
| | |
| | self.building_manager.set_current_building("Test Building 2") |
| | self.assertEqual(self.building_manager.get_current_building(), "Test Building 2") |
| | |
| | |
| | self.building2.settings.floor_area = 200 |
| | self.assertTrue(self.building_manager.update_building(self.building2)) |
| | |
| | |
| | buildings = self.building_manager.get_buildings() |
| | self.assertEqual(buildings["Test Building 2"].settings.floor_area, 200) |
| | |
| | |
| | self.assertTrue(self.building_manager.rename_building("Test Building 3", "Renamed Building")) |
| | |
| | |
| | buildings = self.building_manager.get_buildings() |
| | self.assertNotIn("Test Building 3", buildings) |
| | self.assertIn("Renamed Building", buildings) |
| | |
| | |
| | self.assertTrue(self.building_manager.duplicate_building("Test Building 1", "Duplicated Building")) |
| | |
| | |
| | buildings = self.building_manager.get_buildings() |
| | self.assertIn("Duplicated Building", buildings) |
| | self.assertEqual(buildings["Duplicated Building"].settings.floor_area, 100) |
| | |
| | |
| | result, monthly_breakdown = self.building_manager.calculate_building("Test Building 1") |
| | |
| | |
| | self.assertIsNotNone(result) |
| | self.assertIsNotNone(monthly_breakdown) |
| | |
| | |
| | results = self.building_manager.get_results() |
| | monthly_breakdowns = self.building_manager.get_monthly_breakdowns() |
| | |
| | self.assertIn("Test Building 1", results) |
| | self.assertIn("Test Building 1", monthly_breakdowns) |
| | |
| | |
| | self.assertTrue(self.building_manager.remove_building("Test Building 1")) |
| | |
| | |
| | buildings = self.building_manager.get_buildings() |
| | self.assertNotIn("Test Building 1", buildings) |
| | |
| | |
| | results = self.building_manager.get_results() |
| | monthly_breakdowns = self.building_manager.get_monthly_breakdowns() |
| | |
| | self.assertNotIn("Test Building 1", results) |
| | self.assertNotIn("Test Building 1", monthly_breakdowns) |
| | |
| | def test_end_to_end_workflow(self): |
| | """Test end-to-end workflow.""" |
| | |
| | building1 = self._create_test_building("Office Building", "New York", 1000) |
| | building2 = self._create_test_building("Retail Building", "Chicago", 1500) |
| | |
| | |
| | result1 = calculate_cooling_load(building1) |
| | result2 = calculate_cooling_load(building2) |
| | |
| | |
| | monthly_breakdown1 = calculate_monthly_breakdown(building1) |
| | monthly_breakdown2 = calculate_monthly_breakdown(building2) |
| | |
| | |
| | report1 = generate_monthly_report(building1, monthly_breakdown1) |
| | report2 = generate_monthly_report(building2, monthly_breakdown2) |
| | |
| | |
| | json_str1 = export_building_to_json(building1) |
| | json_str2 = export_building_to_json(building2) |
| | |
| | |
| | with open(os.path.join("test_output", "building1.json"), "w") as f: |
| | f.write(json_str1) |
| | |
| | with open(os.path.join("test_output", "building2.json"), "w") as f: |
| | f.write(json_str2) |
| | |
| | |
| | imported_building1 = import_building_from_json(json_str1) |
| | imported_building2 = import_building_from_json(json_str2) |
| | |
| | |
| | imported_result1 = calculate_cooling_load(imported_building1) |
| | imported_result2 = calculate_cooling_load(imported_building2) |
| | |
| | |
| | self.assertEqual(result1.peak_total_load, imported_result1.peak_total_load) |
| | self.assertEqual(result2.peak_total_load, imported_result2.peak_total_load) |
| | |
| | |
| | archive1 = create_project_archive(building1, result1, monthly_breakdown1) |
| | archive2 = create_project_archive(building2, result2, monthly_breakdown2) |
| | |
| | |
| | with open(os.path.join("test_output", "project1.zip"), "wb") as f: |
| | f.write(archive1) |
| | |
| | with open(os.path.join("test_output", "project2.zip"), "wb") as f: |
| | f.write(archive2) |
| | |
| | |
| | self.assertTrue(os.path.exists(os.path.join("test_output", "building1.json"))) |
| | self.assertTrue(os.path.exists(os.path.join("test_output", "building2.json"))) |
| | self.assertTrue(os.path.exists(os.path.join("test_output", "project1.zip"))) |
| | self.assertTrue(os.path.exists(os.path.join("test_output", "project2.zip"))) |
| | |
| | |
| | building_manager = BuildingManager() |
| | building_manager.add_building(building1) |
| | building_manager.add_building(building2) |
| | |
| | |
| | buildings = building_manager.get_buildings() |
| | self.assertEqual(len(buildings), 2) |
| | self.assertIn("Office Building", buildings) |
| | self.assertIn("Retail Building", buildings) |
| |
|
| | if __name__ == "__main__": |
| | unittest.main() |
| |
|