Datasets:
File size: 2,353 Bytes
870b85a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import unittest
import proportions as pr
def plan(rooms, bedrooms=3):
rows = [dict(room_id=i, room_type=t, bounds_m=b) for i, t, b in rooms]
return dict(rooms=rows)
# 119 m2, three bedrooms (positions do not matter to proportions, only sizes do)
OK = [('living', 'living_room', [0, 0, 6, 4.8]), ('dining', 'dining_room', [6, 0, 10, 4.8]), ('kitchen', 'kitchen', [10, 0, 13.2, 3]),
('bath', 'bathroom', [10, 3, 12.6, 5.4]), ('master', 'master_bedroom', [0, 5, 4.8, 9.2]), ('guest', 'guest_bedroom', [5, 5, 9, 8.6]),
('bedroom_3', 'guest_bedroom', [9, 5.4, 12.8, 8.8]), ('balcony', 'balcony', [0, 9.2, 4.2, 11])]
class Proportions(unittest.TestCase):
def test_an_ordinary_three_bedroom_flat_passes_its_tier(self):
self.assertEqual(pr.problems(plan(OK), '120'), [])
def test_the_total_area_decides_the_tier(self):
self.assertTrue(any(p.startswith('total_area') for p in pr.problems(plan(OK), '100')))
self.assertTrue(any(p.startswith('total_area') for p in pr.problems(plan(OK), '150')))
def test_an_oversized_bathroom_and_a_stub_hallway_are_named(self):
rooms = [list(r) for r in OK]
rooms[3][2] = [10, 3, 13.6, 7] # 14 m2 bathroom
rooms.append(('hallway', 'hallway', [0, 12, 2.0, 13.0])) # 2 m2 hallway
found = pr.problems(plan([tuple(r) for r in rooms]), '120')
self.assertIn('bath_area_large', found)
self.assertIn('hallway_area_small', found)
def test_two_hallways_are_refused(self):
rooms = list(OK) + [('hallway', 'hallway', [0, 12, 3.5, 14]), ('hallway_2', 'hallway', [3.5, 12, 7, 14])]
self.assertIn('more_than_one_hallway', pr.problems(plan(rooms), '120'))
def test_the_living_room_may_not_be_smaller_than_the_master(self):
rooms = [list(r) for r in OK]
rooms[0][2] = [0, 0, 3.5, 4.8]
self.assertIn('living_smaller_than_master', pr.problems(plan([tuple(r) for r in rooms]), '120'))
def test_a_long_thin_bedroom_is_elongated(self):
rooms = [list(r) for r in OK]
rooms[5][2] = [5, 5, 11, 7.9] # 5.4 x 3 = 16 m2, 6 x 2.9 is a ratio of 2.1
self.assertIn('guest_elongated', pr.problems(plan([tuple(r) for r in rooms]), '120'))
if __name__ == '__main__':
unittest.main()
|