2020-day18: balanced parens calculator... gross initial solution...

This commit is contained in:
alexchao26
2020-12-18 01:16:23 -05:00
parent bf9d5a97e7
commit a5e3c80111
2 changed files with 219 additions and 13 deletions
+57 -2
View File
@@ -1,7 +1,10 @@
package main
import (
"reflect"
"testing"
"github.com/alexchao26/advent-of-code-go/util"
)
func Test_part1(t *testing.T) {
@@ -10,7 +13,9 @@ func Test_part1(t *testing.T) {
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
// {"example1", "2 * 3 + (4 * 5)", 26},
{"example2", "((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2", 13632},
{"actual", util.ReadFile("input.txt"), 53660285675207},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -27,7 +32,7 @@ func Test_part2(t *testing.T) {
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
{"actual", util.ReadFile("input.txt"), 141993988282687},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -37,3 +42,53 @@ func Test_part2(t *testing.T) {
})
}
}
func Test_handleFlat(t *testing.T) {
type args struct {
input []string
}
tests := []struct {
name string
args args
want string
}{
{"example", args{
input: []string{"1", "+", "3", "*", "4", "+", "5"},
},
"36",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := handleFlat(tt.args.input); !reflect.DeepEqual(got, tt.want) {
t.Errorf("handleFlat() = %v, want %v", got, tt.want)
}
})
}
}
func Test_splice(t *testing.T) {
type args struct {
sli []string
startIndex int
items int
}
tests := []struct {
name string
args args
want []string
}{
{"example1", args{[]string{"a", "b", "c", "d", "e"}, 1, 1}, []string{"a", "c", "d", "e"}},
{"example1", args{[]string{"a", "b", "c", "d", "e"}, 1, 4}, []string{"a"}},
{"example1", args{[]string{"a", "b", "c", "d", "e"}, 0, 1}, []string{"b", "c", "d", "e"}},
{"example1", args{[]string{"a", "b", "c", "d", "e"}, 0, 5}, []string{}},
{"example1", args{[]string{"a", "b", "c", "d", "e"}, 3, 1}, []string{"a", "b", "c", "e"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := splice(tt.args.sli, tt.args.startIndex, tt.args.items); !reflect.DeepEqual(got, tt.want) {
t.Errorf("splice() = %v, want %v", got, tt.want)
}
})
}
}