-
Notifications
You must be signed in to change notification settings - Fork 0
/
day24_test.go
62 lines (58 loc) · 1.42 KB
/
day24_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
package main
import (
"fmt"
"strings"
"testing"
)
func TestDay24a(t *testing.T) {
tt := []struct {
min bool
expect int
}{
{min: false, expect: 92969593497992},
{min: true, expect: 81514171161381},
}
alu := day24alu()
for i, tc := range tt {
t.Run(fmt.Sprintf("case %d", i+1), func(t *testing.T) {
result := day24a(alu, tc.min)
if tc.expect != result {
t.Fatalf("expected %v, got %v", tc.expect, result)
}
})
}
}
func TestDay24Alu(t *testing.T) {
tt := []struct {
program string
inputs []int
w, x, y, z int
}{
{"inp w", []int{5}, 5, 0, 0, 0},
{"inp w\ninp x\ninp y\ninp z", []int{1, 2, 3, 4}, 1, 2, 3, 4},
{"inp z\ninp x\nmul z 3\neql z x", []int{2, 6}, 0, 6, 0, 1},
{"inp w\nadd w 2", []int{5}, 7, 0, 0, 0},
{"inp w\nmul w 3", []int{2}, 6, 0, 0, 0},
{"inp w\ndiv w 3", []int{9}, 3, 0, 0, 0},
{"inp w\nmod w 3", []int{4}, 1, 0, 0, 0},
{"inp w\nadd x w\neql w x", []int{3}, 1, 3, 0, 0},
}
for i, tc := range tt {
t.Run(fmt.Sprintf("case %d", i+1), func(t *testing.T) {
alu := NewALU(strings.NewReader(tc.program))
alu.run(tc.inputs)
if tc.w != alu.w {
t.Fatalf("expected w to be %d, got %d", tc.w, alu.w)
}
if tc.x != alu.x {
t.Fatalf("expected x to be %d, got %d", tc.x, alu.x)
}
if tc.y != alu.y {
t.Fatalf("expected y to be %d, got %d", tc.y, alu.y)
}
if tc.z != alu.z {
t.Fatalf("expected z to be %d, got %d", tc.z, alu.z)
}
})
}
}