Changed NearestInSpan to NearestWithinSpan and added panic for out of range

This commit is contained in:
btracey
2013-07-26 17:46:59 -07:00
parent bf960529ac
commit f35f141977
4 changed files with 51 additions and 19 deletions

View File

@@ -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)
}