-
Notifications
You must be signed in to change notification settings - Fork 0
/
triangle_test.py
82 lines (54 loc) · 2.39 KB
/
triangle_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import unittest
from triangle import (
equilateral,
isosceles,
scalene,
)
# Tests adapted from `problem-specifications//canonical-data.json`
class EquilateralTriangleTest(unittest.TestCase):
def test_all_sides_are_equal(self):
self.assertIs(equilateral([2, 2, 2]), True)
def test_any_side_is_unequal(self):
self.assertIs(equilateral([2, 3, 2]), False)
def test_no_sides_are_equal(self):
self.assertIs(equilateral([5, 4, 6]), False)
def test_all_zero_sides_is_not_a_triangle(self):
self.assertIs(equilateral([0, 0, 0]), False)
def test_sides_may_be_floats(self):
self.assertIs(equilateral([0.5, 0.5, 0.5]), True)
class IsoscelesTriangleTest(unittest.TestCase):
def test_last_two_sides_are_equal(self):
self.assertIs(isosceles([3, 4, 4]), True)
def test_first_two_sides_are_equal(self):
self.assertIs(isosceles([4, 4, 3]), True)
def test_first_and_last_sides_are_equal(self):
self.assertIs(isosceles([4, 3, 4]), True)
def test_equilateral_triangles_are_also_isosceles(self):
self.assertIs(isosceles([4, 4, 4]), True)
def test_no_sides_are_equal(self):
self.assertIs(isosceles([2, 3, 4]), False)
def test_first_triangle_inequality_violation(self):
self.assertIs(isosceles([1, 1, 3]), False)
def test_second_triangle_inequality_violation(self):
self.assertIs(isosceles([1, 3, 1]), False)
def test_third_triangle_inequality_violation(self):
self.assertIs(isosceles([3, 1, 1]), False)
def test_sides_may_be_floats(self):
self.assertIs(isosceles([0.5, 0.4, 0.5]), True)
class ScaleneTriangleTest(unittest.TestCase):
def test_no_sides_are_equal(self):
self.assertIs(scalene([5, 4, 6]), True)
def test_all_sides_are_equal(self):
self.assertIs(scalene([4, 4, 4]), False)
def test_first_and_second_sides_are_equal(self):
self.assertIs(scalene([4, 4, 3]), False)
def test_first_and_third_sides_are_equal(self):
self.assertIs(scalene([3, 4, 3]), False)
def test_second_and_third_sides_are_equal(self):
self.assertIs(scalene([4, 3, 3]), False)
def test_may_not_violate_triangle_inequality(self):
self.assertIs(scalene([7, 3, 2]), False)
def test_sides_may_be_floats(self):
self.assertIs(scalene([0.5, 0.4, 0.6]), True)
if __name__ == "__main__":
unittest.main()