-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
63 lines (50 loc) · 2.01 KB
/
test.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
import unittest
from solution import visible_area
import random
class TestVisibleArea(unittest.TestCase):
def test_basic_functionality(self):
mountains = [
{'left': 9, 'right': 15, 'height': 3},
{'left': 8, 'right': 14, 'height': 3},
{'left': 0, 'right': 6, 'height': 3},
]
self.assertEqual(visible_area(mountains), 20.75)
def test_max_qty_same_mountain(self):
mnt_1 = {'left': 0, 'right': 6, 'height': 3}
mountains = [mnt_1.copy() for _ in range(1000)]
self.assertEqual(visible_area(mountains), 9)
def test_one_mountain(self):
mountains = [{'left': 0, 'right': 6, 'height': 3}]
self.assertEqual(visible_area(mountains), 9)
def test_none_mountain(self):
mountains = []
self.assertEqual(visible_area(mountains), 0)
def test_boundary_conditions(self):
mountains = [{'left': 0, 'right': 100000, 'height': 50000}]
self.assertEqual(visible_area(mountains), 2500000000)
def test_hidden_mountain(self):
mountains = [
{'left': 0, 'right': 6, 'height': 3},
{'left': 2, 'right': 4, 'height': 1}
]
self.assertEqual(visible_area(mountains), 9)
def test_random_mountains_consistency(self):
random.seed(42)
mountains = []
for _ in range(10):
height = random.randint(1, 50000)
left = random.randint(0, 100000 - 2 * height)
right = left + 2 * height
mountains.append({'left': left, 'right': right, 'height': height})
area1 = visible_area(mountains)
random.seed(42)
mountains = []
for _ in range(10):
height = random.randint(1, 50000)
left = random.randint(0, 100000 - 2 * height)
right = left + 2 * height
mountains.append({'left': left, 'right': right, 'height': height})
area2 = visible_area(mountains)
self.assertEqual(area1, area2)
if __name__ == '__main__':
unittest.main()