Add tests for bisect

This commit is contained in:
c-bata 2017-08-15 01:50:21 +09:00
parent bd6a548700
commit ba4f3458b5
2 changed files with 21 additions and 3 deletions

View File

@ -2,9 +2,6 @@ package prompt
import "sort"
// Thanks!! https://play.golang.org/p/y9NRj_XVIW
// TODO: Add unit tests
// BisectLeft to Locate the insertion point for v in a to maintain sorted order.
func BisectLeft(a []int, v int) int {
return bisectLeftRange(a, v, 0, len(a))

21
bisect_test.go Normal file
View File

@ -0,0 +1,21 @@
package prompt
import (
"testing"
)
// Thanks!! https://play.golang.org/p/y9NRj_XVIW
func TestBisectRight(t *testing.T) {
in := []int{1, 2, 3, 3, 3, 6, 7}
r := BisectRight(in, 0)
if r != 0 {
t.Error("number 0 should inserted at 0 position, but got %d", r)
}
r = BisectRight(in, 4)
if r != 5 {
t.Error("number 4 should inserted at 5 position, but got %d", r)
}
}