1010kDt = 0.01 # 10 ms
1111
1212
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-
2413def test_reaches_goal ():
2514 constraints = TrapezoidProfile .Constraints (1.75 , 0.75 )
2615 goal = TrapezoidProfile .State (3.0 , 0.0 )
@@ -48,7 +37,10 @@ def test_pos_continuous_under_vel_change():
4837 estimated_vel = (state .position - last_pos ) / kDt
4938
5039 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 )
5244 assert state .velocity <= constraints .maxVelocity
5345
5446 last_pos = state .position
@@ -92,7 +84,7 @@ def test_top_speed():
9284
9385 for _ in range (200 ):
9486 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 )
9688
9789 profile = TrapezoidProfile (constraints )
9890 for _ in range (2000 ):
@@ -108,7 +100,7 @@ def test_timing_to_current():
108100
109101 for _ in range (400 ):
110102 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 )
112104
113105
114106def test_timing_to_goal ():
@@ -178,5 +170,5 @@ def test_timing_before_negative_goal():
178170def test_initialization_of_current_state ():
179171 constraints = TrapezoidProfile .Constraints (1.0 , 1.0 )
180172 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