-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_test.go
108 lines (95 loc) · 1.95 KB
/
01_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestAOC202201Helper(t *testing.T) {
var tests = []struct {
input string
output []int
outputErr bool
}{
{
input: `
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000`,
output: []int{4000, 6000, 10000, 11000, 24000},
},
{
input: ``,
output: nil,
outputErr: false,
},
{
input: `Pinselohrkatze`,
output: nil,
outputErr: true,
},
}
for _, test := range tests {
want := test.output
got, err := AOC202201Helper(test.input)
if err != nil && !test.outputErr {
t.Fatalf("AOC2022011Helper(%+v) err: %v", test.input, err)
}
if err == nil && test.outputErr {
t.Fatalf("AOC2022011Helper(%+v) should return an error instead of %d", test.input, test.output)
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("AOC2022011Helper(%+v) missmatch (-want +got):\n%s", test.input, diff)
}
}
}
func TestAOC202201SumMaxN(t *testing.T) {
var tests = []struct {
input []int
inputN int
output int
outputErr bool
}{
{
input: []int{1, 2, 3, 4},
inputN: 1,
output: 4,
outputErr: false,
},
{
input: []int{1, 2, 3, 4},
inputN: 4,
output: 10,
outputErr: false,
},
{
input: []int{1, 2, 3, 4},
inputN: 0,
output: 0,
outputErr: false,
},
{
input: []int{1, 2, 3, 4},
inputN: 5,
output: 0,
outputErr: true,
},
}
for _, test := range tests {
got, err := AOC202201SumMaxN(test.input, test.inputN)
if err != nil && !test.outputErr {
t.Fatalf("AOC202201SumMaxN(%+v, %d) err: %v", test.input, test.inputN, err)
}
if err == nil && test.outputErr {
t.Fatalf("AOC202201SumMaxN(%+v, %d) should return an error instead of %d", test.input, test.inputN, test.output)
}
if got != test.output {
t.Errorf("AOC202201SumMaxN(%+v, %d) missmatch:\nwant: %d\ngot: %d", test.input, test.inputN, test.output, got)
}
}
}