mirror of
https://github.com/gonum/gonum.git
synced 2025-10-09 09:00:38 +08:00
Changed NearestInSpan to NearestWithinSpan and added panic for out of range
This commit is contained in:
@@ -318,32 +318,31 @@ func TestNearest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNearestInSpan(t *testing.T) {
|
||||
ind := NearestInSpan(13, 7, 8.2, -1)
|
||||
if ind != 0 {
|
||||
t.Errorf("Wrong value when below the lower bound. %i found, %i expected", ind, 0)
|
||||
func TestNearestWithinSpan(t *testing.T) {
|
||||
|
||||
if !Panics(func() { NearestWithinSpan(13, 7, 8.2, 10) }) {
|
||||
t.Errorf("Did not panic below lower bound")
|
||||
}
|
||||
ind = NearestInSpan(13, 7, 8.2, 9)
|
||||
if ind != 12 {
|
||||
t.Errorf("Wrong value when above the upper bound. %i found, %i expected", ind, 12)
|
||||
if !Panics(func() { NearestWithinSpan(13, 7, 8.2, 10) }) {
|
||||
t.Errorf("Did not panic above upper bound")
|
||||
}
|
||||
ind = NearestInSpan(13, 7, 8.2, 7.19)
|
||||
ind := NearestWithinSpan(13, 7, 8.2, 7.19)
|
||||
if ind != 2 {
|
||||
t.Errorf("Wrong value when just below the bucket. %i found, %i expected", ind, 2)
|
||||
}
|
||||
ind = NearestInSpan(13, 7, 8.2, 7.21)
|
||||
ind = NearestWithinSpan(13, 7, 8.2, 7.21)
|
||||
if ind != 2 {
|
||||
t.Errorf("Wrong value when just above the bucket. %i found, %i expected", ind, 2)
|
||||
}
|
||||
ind = NearestInSpan(13, 7, 8.2, 7.2)
|
||||
ind = NearestWithinSpan(13, 7, 8.2, 7.2)
|
||||
if ind != 2 {
|
||||
t.Errorf("Wrong value when equal to bucket. %i found, %i expected", ind, 2)
|
||||
}
|
||||
ind = NearestInSpan(13, 7, 8.2, 7.151)
|
||||
ind = NearestWithinSpan(13, 7, 8.2, 7.151)
|
||||
if ind != 2 {
|
||||
t.Errorf("Wrong value when just above halfway point. %i found, %i expected", ind, 2)
|
||||
}
|
||||
ind = NearestInSpan(13, 7, 8.2, 7.249)
|
||||
ind = NearestWithinSpan(13, 7, 8.2, 7.249)
|
||||
if ind != 2 {
|
||||
t.Errorf("Wrong value when just below halfway point. %i found, %i expected", ind, 2)
|
||||
}
|
||||
|
Reference in New Issue
Block a user