-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1_test.go
58 lines (53 loc) · 1.05 KB
/
day1_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
package main
import (
"fmt"
"strconv"
"strings"
"testing"
)
func TestSum(t *testing.T) {
testCases := []struct {
x int
y int
z int
want int
}{
{+1, +1, +1, 3},
{+1, +1, -2, 0},
{-1, -2, -3, -6},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%d+%d+%d", tc.x, tc.y, tc.z), func(t *testing.T) {
frequencies := ComputeFrequencies(tc.x, tc.y, tc.z)
got := frequencies[len(frequencies)-1]
if got != tc.want {
t.Errorf("got %d; want %d", got, tc.want)
}
})
}
}
func TestFindFirstDuplicate(t *testing.T) {
testCases := []struct {
list []int
want int
}{
{[]int{+1, -1}, 0},
{[]int{+3, +3, +4, -2, -4}, 10},
{[]int{-6, +3, +8, +5, -6}, 5},
{[]int{+7, +7, -2, -7, -4}, 14},
}
for _, tc := range testCases {
var strs []string
for _, num := range tc.list {
s := strconv.Itoa(num)
strs = append(strs, s)
}
name := strings.Join(strs, "_")
t.Run(name, func(t *testing.T) {
got := FindFirstDuplicate(tc.list...)
if got != tc.want {
t.Errorf("got %d; want %d", got, tc.want)
}
})
}
}