-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestControl.py
113 lines (95 loc) · 3.64 KB
/
TestControl.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#Matthew Luerman
#PSet 1
#8 February 2018
import unittest
import random
import math
from Control import Control
random.seed(125)
class TestControl(unittest.TestCase):
"""
Tests for the Control class. Checks responses to initialization with valid and invalid parameters, as well as
nominal functioning of the getSpeed() and getRotVel() methods.
"""
def testInputs_nominal(self):
"""Tests creation of Control instance with valid inputs"""
s = random.uniform(5, 10)
w = random.uniform(-math.pi/4, math.pi/4)
c = Control(s, w)
self.assertEqual(c.s, s)
self.assertEqual(c.omega, w)
def testInputS_low(self):
"""Tests creation of Control instance with invalid s parameter"""
s = 4.9
w = random.uniform(-math.pi/4, math.pi/4)
with self.assertRaises(ValueError):
c = Control(s, w)
def testInputS_high(self):
"""Tests creation of Control instance with invalid s parameter"""
s = 10.1
w = random.uniform(-math.pi/4, math.pi/4)
with self.assertRaises(ValueError):
c = Control(s, w)
def testInputS_edgelow(self):
"""Tests creation of Control instance with edge case s parameter"""
s = 5
w = random.uniform(-math.pi/4, math.pi/4)
c = Control(s, w)
self.assertEqual(c.s, s)
def testInputS_edgehigh(self):
"""Tests creation of Control instance with edge case s parameter"""
s = 10
w = random.uniform(-math.pi/4, math.pi/4)
c = Control(s, w)
self.assertEqual(c.s, s)
def testInputS_wrongtype(self):
"""Tests creation of a Control class instance with an invalid speed input"""
s = 'input test'
w = random.uniform(-math.pi/4, math.pi/4)
with self.assertRaises(TypeError):
c = Control(s, w)
def testInputOmega_low(self):
"""Tests creation of Control instance with invalid omega parameter"""
s = random.uniform(5, 10)
w = -math.pi/4 - .1
with self.assertRaises(ValueError):
c = Control(s, w)
def testInputOmega_high(self):
"""Tests creation of Control instance with invalid omega parameter"""
s = random.uniform(5, 10)
w = math.pi/4 + .1
with self.assertRaises(ValueError):
c = Control(s, w)
def testInputOmega_edgelow(self):
"""Tests creation of Control instance with edge case omega parameter"""
s = random.uniform(5, 10)
w = -math.pi/4
c = Control(s, w)
self.assertEqual(c.s, s)
def testInputOmega_edgehigh(self):
"""Tests creation of Control instance with edge case omega parameter"""
s = random.uniform(5, 10)
w = math.pi/4
c = Control(s, w)
self.assertEqual(c.s, s)
def testInputOmega_wrongtype(self):
"""Tests creation of Control instance with invalid omega parameter"""
s = random.uniform(5, 10)
w = 'test input'
with self.assertRaises(TypeError):
c = Control(s, w)
def testGetSpeed(self):
"""Tests nominal functioning of getSpeed() method"""
s = random.uniform(5, 10)
w = random.uniform(-math.pi/4, math.pi/4)
c = Control(s, w)
self.assertEqual(c.getSpeed(), s)
def testGetRotVel(self):
"""Tests nominal functioning of getRotVel() method"""
s = random.uniform(5, 10)
w = random.uniform(-math.pi/4, math.pi/4)
c = Control(s, w)
self.assertEqual(c.getRotVel(), w)
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(TestControl)
unittest.TextTestRunner().run(suite)