-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathsolution_test.go
More file actions
44 lines (40 loc) · 814 Bytes
/
solution_test.go
File metadata and controls
44 lines (40 loc) · 814 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
44
package main
import (
"fmt"
"reflect"
"testing"
)
type TestItemInput struct {
nums []int
target 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 := twoSum(v.input.nums, v.input.target)
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{2, 7, 11, 15}, target: 9},
output: []int{0, 1},
},
{
input: TestItemInput{nums: []int{3, 2, 4}, target: 6},
output: []int{1, 2},
},
{
input: TestItemInput{nums: []int{3, 3}, target: 6},
output: []int{0, 1},
},
}
}