10
10
kDt = 0.01 # 10 ms
11
11
12
12
13
- def expect_near_units (val1 , val2 , eps ):
14
- assert abs (val1 - val2 ) <= eps
15
-
16
-
17
- def expect_lt_or_near_units (val1 , val2 , eps ):
18
- if val1 <= val2 :
19
- assert val1 <= val2
20
- else :
21
- expect_near_units (val1 , val2 , eps )
22
-
23
-
24
13
def test_reaches_goal ():
25
14
constraints = TrapezoidProfile .Constraints (1.75 , 0.75 )
26
15
goal = TrapezoidProfile .State (3.0 , 0.0 )
@@ -48,7 +37,10 @@ def test_pos_continuous_under_vel_change():
48
37
estimated_vel = (state .position - last_pos ) / kDt
49
38
50
39
if i >= 400 :
51
- expect_lt_or_near_units (estimated_vel , constraints .maxVelocity , 1e-4 )
40
+ if estimated_vel <= constraints .maxVelocity :
41
+ assert estimated_vel <= constraints .maxVelocity
42
+ else :
43
+ math .isclose (estimated_vel , constraints .maxVelocity , abs_tol = 1e-4 )
52
44
assert state .velocity <= constraints .maxVelocity
53
45
54
46
last_pos = state .position
@@ -92,7 +84,7 @@ def test_top_speed():
92
84
93
85
for _ in range (200 ):
94
86
state = profile .calculate (kDt , state , goal )
95
- expect_near_units (constraints .maxVelocity , state .velocity , 1e-4 )
87
+ assert math . isclose (constraints .maxVelocity , state .velocity , abs_tol = 1e-4 )
96
88
97
89
profile = TrapezoidProfile (constraints )
98
90
for _ in range (2000 ):
@@ -108,7 +100,7 @@ def test_timing_to_current():
108
100
109
101
for _ in range (400 ):
110
102
state = profile .calculate (kDt , state , goal )
111
- expect_near_units (profile .timeLeftUntil (state .position ), 0.0 , 0.02 )
103
+ assert math . isclose (profile .timeLeftUntil (state .position ), 0.0 , abs_tol = 0.02 )
112
104
113
105
114
106
def test_timing_to_goal ():
@@ -178,5 +170,5 @@ def test_timing_before_negative_goal():
178
170
def test_initialization_of_current_state ():
179
171
constraints = TrapezoidProfile .Constraints (1.0 , 1.0 )
180
172
profile = TrapezoidProfile (constraints )
181
- expect_near_units (profile .timeLeftUntil (0.0 ), 0.0 , 1e-10 )
182
- expect_near_units (profile .totalTime (), 0.0 , 1e-10 )
173
+ assert math . isclose (profile .timeLeftUntil (0.0 ), 0.0 , abs_tol = 1e-10 )
174
+ assert math . isclose (profile .totalTime (), 0.0 , abs_tol = 1e-10 )
0 commit comments