-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathk_closest_points_to_origin_test.go
36 lines (30 loc) · 1.06 KB
/
k_closest_points_to_origin_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package heap
import (
"reflect"
"testing"
)
/*
TestKClosestPointToOrigin tests solution(s) with the following signature and problem description:
func KClosestPointToOrigin(points [][]int, k int) [][]int
Given coordination of a point on an x,y axis and an integer k, return k closest points to the origin.
For example given {1,1}, {2,2}, {3,3}, {4,4} and k=2, return {1,1}, {2,2}.
*/
func TestKClosestPointToOrigin(t *testing.T) {
tests := []struct {
points [][]int
k int
kthClosest [][]int
}{
{[][]int{{}}, 1, [][]int{{}}},
{[][]int{{10, 10}}, 1, [][]int{{10, 10}}},
{[][]int{{10, 10}, {-10, -10}, {11, 11}, {12, 12}}, 1, [][]int{{10, 10}}},
{[][]int{{10, 10}, {-10, -10}, {11, 11}, {12, 12}}, 2, [][]int{{10, 10}, {-10, -10}}},
{[][]int{{35, 11}, {14, -12}, {50, 100}, {2, 19}, {-17, -18}, {1, 1}, {27, 22}}, 1, [][]int{{1, 1}}},
}
for i, test := range tests {
got := KClosestPointToOrigin(test.points, test.k)
if !reflect.DeepEqual(got, test.kthClosest) {
t.Fatalf("Failed test case #%d. Want %d got %d", i, test.kthClosest, got)
}
}
}