|
|
""" |
|
|
Test house specifications display component |
|
|
""" |
|
|
|
|
|
import sys |
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent)) |
|
|
|
|
|
from components.house_specs_display import format_house_specs_display |
|
|
|
|
|
|
|
|
def test_house_specs_display_with_dict(): |
|
|
"""Test house specifications display with dictionary input""" |
|
|
|
|
|
house_specs = { |
|
|
'number_of_floors': 2, |
|
|
'primary_material': 'reinforced_concrete', |
|
|
'foundation_type': 'deep_pile', |
|
|
'foundation_depth_meters': 3.5, |
|
|
'roof_type': 'hip', |
|
|
'wall_thickness_mm': 250, |
|
|
'reinforcement_details': 'Steel rebar Grade 60, 16mm diameter @ 200mm spacing', |
|
|
'structural_features': [ |
|
|
{ |
|
|
'feature_name': 'Shear Walls', |
|
|
'specification': '300mm thick reinforced concrete shear walls at building corners', |
|
|
'justification': 'Required for high seismic zone to resist lateral forces' |
|
|
}, |
|
|
{ |
|
|
'feature_name': 'Elevated Foundation', |
|
|
'specification': 'First floor elevated 1.5m above ground level', |
|
|
'justification': 'Protection against flood risk identified in the area' |
|
|
} |
|
|
], |
|
|
'compliance_codes': [ |
|
|
'National Building Code of the Philippines (NBCP)', |
|
|
'National Structural Code of the Philippines (NSCP) 2015', |
|
|
'Philippine Green Building Code' |
|
|
], |
|
|
'decision_rationale': 'Based on high seismic risk and moderate flood risk, reinforced concrete with deep pile foundation provides optimal structural integrity. Hip roof design offers superior wind resistance.' |
|
|
} |
|
|
|
|
|
html = format_house_specs_display(house_specs) |
|
|
|
|
|
|
|
|
assert 'ποΈ House Specifications' in html |
|
|
assert '2' in html |
|
|
assert 'Reinforced Concrete' in html |
|
|
assert 'Deep Pile' in html |
|
|
assert '3.50 meters' in html |
|
|
assert 'Hip' in html |
|
|
assert '250 mm' in html |
|
|
assert 'Shear Walls' in html |
|
|
assert 'Elevated Foundation' in html |
|
|
assert 'National Building Code of the Philippines' in html |
|
|
assert 'decision_rationale' in html.lower() or 'rationale' in html.lower() |
|
|
|
|
|
print("β
Test passed: House specifications display with dict") |
|
|
return True |
|
|
|
|
|
|
|
|
def test_house_specs_display_with_none(): |
|
|
"""Test house specifications display with None input""" |
|
|
|
|
|
html = format_house_specs_display(None) |
|
|
|
|
|
|
|
|
assert 'unavailable' in html.lower() |
|
|
|
|
|
print("β
Test passed: House specifications display with None") |
|
|
return True |
|
|
|
|
|
|
|
|
def test_house_specs_display_minimal(): |
|
|
"""Test house specifications display with minimal data""" |
|
|
|
|
|
house_specs = { |
|
|
'number_of_floors': 1, |
|
|
'primary_material': 'wood', |
|
|
'foundation_type': 'shallow', |
|
|
'foundation_depth_meters': 1.0, |
|
|
'roof_type': 'gable', |
|
|
'wall_thickness_mm': 150, |
|
|
'reinforcement_details': '', |
|
|
'structural_features': [], |
|
|
'compliance_codes': [], |
|
|
'decision_rationale': '' |
|
|
} |
|
|
|
|
|
html = format_house_specs_display(house_specs) |
|
|
|
|
|
|
|
|
assert 'ποΈ House Specifications' in html |
|
|
assert '1' in html |
|
|
assert 'Wood' in html |
|
|
assert 'Shallow' in html |
|
|
assert 'Gable' in html |
|
|
|
|
|
print("β
Test passed: House specifications display with minimal data") |
|
|
return True |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
print("Testing house specifications display component...\n") |
|
|
|
|
|
try: |
|
|
test_house_specs_display_with_dict() |
|
|
test_house_specs_display_with_none() |
|
|
test_house_specs_display_minimal() |
|
|
|
|
|
print("\nβ
All tests passed!") |
|
|
|
|
|
except AssertionError as e: |
|
|
print(f"\nβ Test failed: {e}") |
|
|
sys.exit(1) |
|
|
except Exception as e: |
|
|
print(f"\nβ Unexpected error: {e}") |
|
|
import traceback |
|
|
traceback.print_exc() |
|
|
sys.exit(1) |
|
|
|