-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathsolution_test.go
More file actions
43 lines (39 loc) · 785 Bytes
/
solution_test.go
File metadata and controls
43 lines (39 loc) · 785 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
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"reflect"
"testing"
)
type TestItemInput struct {
nums []int
}
type TestItem struct {
input TestItemInput
output [][]int
}
func TestTask(t *testing.T) {
for i, v := range generateTasks() {
t.Run(fmt.Sprintf("Test %d", i+1), func(t *testing.T) {
res := threeSum(v.input.nums)
if !reflect.DeepEqual(res, v.output) {
t.Errorf("Wrong test.\nOutput: \n%v \nExpected: \n%v", res, v.output)
}
})
}
}
func generateTasks() []TestItem {
return []TestItem{
{
input: TestItemInput{nums: []int{-1, 0, 1, 2, -1, -4}},
output: [][]int{{-1, -1, 2}, {-1, 0, 1}},
},
{
input: TestItemInput{nums: []int{0, 1, 1}},
output: nil,
},
{
input: TestItemInput{nums: []int{0, 0, 0}},
output: [][]int{{0, 0, 0}},
},
}
}