-
-
Notifications
You must be signed in to change notification settings - Fork 8
fix: harden spring and views against non-finite values and reschedule ping #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -67,3 +67,31 @@ func TestSpringStableAtUITickInterval(t *testing.T) { | |||||||||||||||||||||||||||||||
| t.Errorf("Spring oscillated negative at dt=0.13 (min %f) — value would render as 0 B/s", minVal) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func TestSpringNaNAndInfGuards(t *testing.T) { | ||||||||||||||||||||||||||||||||
| var vel float64 | ||||||||||||||||||||||||||||||||
| // Target is NaN | ||||||||||||||||||||||||||||||||
| val := Spring(100, math.NaN(), &vel, 0.13) | ||||||||||||||||||||||||||||||||
| if math.IsNaN(val) || math.IsInf(val, 0) { | ||||||||||||||||||||||||||||||||
| t.Errorf("Spring with NaN target returned %f", val) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Current is NaN | ||||||||||||||||||||||||||||||||
| val = Spring(math.NaN(), 100, &vel, 0.13) | ||||||||||||||||||||||||||||||||
| if math.IsNaN(val) || math.IsInf(val, 0) { | ||||||||||||||||||||||||||||||||
| t.Errorf("Spring with NaN current returned %f", val) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Velocity is NaN | ||||||||||||||||||||||||||||||||
| vel = math.NaN() | ||||||||||||||||||||||||||||||||
| val = Spring(100, 100, &vel, 0.13) | ||||||||||||||||||||||||||||||||
| if math.IsNaN(val) || math.IsInf(val, 0) || math.IsNaN(vel) { | ||||||||||||||||||||||||||||||||
| t.Errorf("Spring with NaN velocity returned val=%f, vel=%f", val, vel) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+85
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Strengthen assertion on velocity reset when starting from NaN For the NaN velocity case, the test should assert that
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // dt is NaN | ||||||||||||||||||||||||||||||||
| val = Spring(100, 100, &vel, math.NaN()) | ||||||||||||||||||||||||||||||||
| if math.IsNaN(val) || math.IsInf(val, 0) { | ||||||||||||||||||||||||||||||||
| t.Errorf("Spring with NaN dt returned %f", val) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.