-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculations_test.py
54 lines (42 loc) · 2.05 KB
/
calculations_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
import math
import unittest
import calculations
class TestCalculations(unittest.TestCase):
def test_calculate_slot_angles(self):
# From page 4 of
# https://www.heldermann-verlag.de/jgg/jgg15/j15h1mone.pdf
expected_angles = [76.9, 63.4, 49.1, 33.7, 17.2, 0, -17.2, -33.7,
-49.1, -63.4, -76.9]
actual_angles = [
math.degrees(r)
for r in calculations.slot_angles(12, math.pi / 6)]
self.assertEqual(len(actual_angles), len(expected_angles))
for actual, expected in zip(actual_angles, expected_angles):
self.assertAlmostEqual(actual, expected, places=1)
def test_slot_width(self):
for material_thickness in range(10):
actual_width = calculations.slot_width(material_thickness,
math.radians(90))
self.assertAlmostEqual(actual_width, material_thickness)
actual_width = calculations.slot_width(material_thickness,
math.radians(45))
self.assertAlmostEqual(
actual_width,
material_thickness + math.sqrt(2) * material_thickness)
actual_width = calculations.slot_width(material_thickness,
math.radians(180 - 45))
self.assertAlmostEqual(
actual_width,
material_thickness + math.sqrt(2) * material_thickness)
actual_width = calculations.slot_width(material_thickness,
math.radians(60))
self.assertAlmostEqual(
actual_width,
3 * material_thickness / math.sqrt(3))
actual_width = calculations.slot_width(material_thickness,
math.radians(180 - 60))
self.assertAlmostEqual(
actual_width,
3 * material_thickness / math.sqrt(3))
if __name__ == '__main__':
unittest.main()