generated from ISP21/triangle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameterized_test.py
50 lines (44 loc) · 1.31 KB
/
parameterized_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
import unittest
from triangle import is_triangle
class TriangleTest(unittest.TestCase):
valid_triangles = [
(1, 1, 1),
(3, 4, 5),
(3, 4, 6),
(8, 10, 12),
(100, 101, 200),
(0.9, 1.0, 1.1)
]
not_triangles = [
(21, 10, 10),
(2, 1, 1), # borderline case
(6, 10, 4), # borderline case
(6, 20, 4),
(2, 3, 10)
]
invalid_arguments = [
(-1, 2, 2),
(1, 0, 2),
(1, -1, 2),
(1, 0, 2),
(1, 2, -1),
(1, 2, 0),
(-1, -1, -1),
(0, 0, 0)
]
def test_valid_triangle(self):
for a, b, c in self.valid_triangles:
with self.subTest():
msg = f"side lengths ({a},{b},{c})"
self.assertTrue(is_triangle(a, b, c), msg)
def test_not_triangle(self):
for a, b, c in self.not_triangles:
with self.subTest():
msg = f"side lengths ({a},{b},{c})"
self.assertFalse(is_triangle(a, b, c), msg)
def test_invalid_argument_raises_exception(self):
"""any non-positive argument should raise ValueError"""
for a, b, c in self.invalid_arguments:
with self.subTest():
with self.assertRaises(ValueError):
b = is_triangle(a, b, c)