forked from NicholsSchool/2022-EV3-Lego-Robotic-Arm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
math_helper.py
40 lines (32 loc) · 1.03 KB
/
math_helper.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
import unittest
from math_helper import scale, scale_stick
VALID_DEFAULT_INPUT = [
(0, -80),
(136, 0),
(255, 80),
(128, 0)
]
VALID_DEADZONE_INPUT = [
(0, 0, -80),
(255, 0, 80),
(128, 0, 0),
(136, 10, 0),
(140, 10, 0),
(140, 5, 7),
(150, 10, 14),
(255, 0, 80),
(128, 0, 0),
]
class TestMathHelper(unittest.TestCase):
def test_scale_stick_default(self):
for input_set in VALID_DEFAULT_INPUT:
with self.subTest(data=input_set):
self.assertEqual(scale_stick(input_set[0]), input_set[1])
def test_scale_stick_default_inverted(self):
for input_set in VALID_DEFAULT_INPUT:
with self.subTest(data=input_set):
self.assertEqual(scale_stick(input_set[0], invert=True), -input_set[1])
def test_scale_stick_deadzone(self):
for input_set in VALID_DEADZONE_INPUT:
with self.subTest(data=input_set):
self.assertEqual(int(scale_stick(input_set[0], deadzone=input_set[1])), input_set[2])