From ba4f3458b5bb84572e9d4dbc928df30583dc02d8 Mon Sep 17 00:00:00 2001 From: c-bata Date: Tue, 15 Aug 2017 01:50:21 +0900 Subject: [PATCH] Add tests for bisect --- bisect.go | 3 --- bisect_test.go | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 bisect_test.go diff --git a/bisect.go b/bisect.go index b4f929a..2bcef3a 100644 --- a/bisect.go +++ b/bisect.go @@ -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)) diff --git a/bisect_test.go b/bisect_test.go new file mode 100644 index 0000000..0baed7c --- /dev/null +++ b/bisect_test.go @@ -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) + } +}