-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathsum_up_to_k_test.go
More file actions
34 lines (28 loc) · 810 Bytes
/
sum_up_to_k_test.go
File metadata and controls
34 lines (28 loc) · 810 Bytes
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
package hashtable
import (
"slices"
"testing"
)
/*
TestSumUpToK tests solution(s) with the following signature and problem description:
func SumUpToK(numbers []int, k int) []int
Given a slice of integers, output the indices of the first two elements that sum up to K.
For example given {1, 2, 3, 4} and K = 5, return {1, 2} because 2 + 3 = 5.
*/
func TestSumUpToK(t *testing.T) {
tests := []struct {
k int
numbers, indices []int
}{
{6, []int{3, 3}, []int{0, 1}},
{3, []int{1, 2, 3, 4}, []int{0, 1}},
{5, []int{1, 2, 3, 6}, []int{1, 2}},
{7, []int{1, 2, 3, 4}, []int{2, 3}},
}
for i, test := range tests {
got := SumUpToK(test.numbers, test.k)
if !slices.Equal(got, test.indices) {
t.Fatalf("Failed test case #%d. Want %#v got %#v", i, test.indices, got)
}
}
}