practice / tests /test_zoning_check.py
birgermoell's picture
Add Practice generators, indices, verification and documentation
2983a9c verified
Raw History Blame Contribute Delete
1.39 kB
"""Hand-worked checks for the fictional code; no external zoning rules apply."""
import sys
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
from envs.zoning_check.gen import polygon_area,capacity,parking,compliance
# Rectangles 10*20, translated triangle base 6 height 4 / 2, L shape 100-36.
assert polygon_area([(0,0),(10,0),(10,20),(0,20)])==200
assert polygon_area([(3,2),(9,2),(3,6)])==12
assert polygon_area([(0,0),(10,0),(10,4),(4,4),(4,10),(0,10)])==64
# Reversing orientation cannot change area.
assert polygon_area([(0,10),(4,10),(4,4),(10,4),(10,0),(0,0)])==64
# 50*50: 1 floor binds coverage at 1000; 4 floors bind FAR at 3000.
assert capacity(50,50,1)[:2]==(1000,'coverage')
assert capacity(50,50,4)[:2]==(3000,'far')
# Narrow plot: setback envelope 2*42*2=168.
assert capacity(10,50,2)[:2]==(168,'setbacks')
# Ceiling once: 1.5+1+1=3.5 -> 4; 3+1+1=5; 4.5+.5+.5=5.5 -> 6.
assert parking(1,40,60)==4
assert parking(2,40,60)==5
assert parking(3,20,30)==6
row=dict(width_m=20,depth_m=20,gross_floor_m2=480,footprint_m2=160,height_m=15,front_m=4,rear_m=4,left_m=4,right_m=4)
assert compliance(row)==(400,1.2,.4,[])
assert compliance(dict(row,gross_floor_m2=500,front_m=3))[3]==['far','setback']
assert compliance(dict(row,footprint_m2=200,height_m=18))[3]==['coverage','height']
print('zoning_check: 3 hand-worked cases per family passed')