updated template script for test args order

This commit is contained in:
alexchao26
2020-12-13 02:34:03 -05:00
parent 9e86d9784d
commit eb2eacdf9e
26 changed files with 333 additions and 362 deletions
+2 -7
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -33,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+2 -7
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -33,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+2 -7
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -33,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+2 -7
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -33,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+2 -7
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -33,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+2 -7
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -33,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+1 -7
View File
@@ -34,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+1 -7
View File
@@ -34,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+1 -7
View File
@@ -34,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+1 -7
View File
@@ -34,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+1 -7
View File
@@ -34,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+1 -7
View File
@@ -34,19 +34,13 @@ func part1(input string) int {
}
func part2(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func parseInput(input string) []int {
var ans []int
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
}
return ans
}
+17 -19
View File
@@ -1,18 +1,18 @@
package main
import "testing"
import (
"testing"
)
var tests1 = []struct {
func Test_part1(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart1(t *testing.T) {
for _, tt := range tests1 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
}
}
var tests2 = []struct {
func Test_part2(t *testing.T) {
tests := []struct {
name string
want int
input string
// add extra args if needed
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
}
func TestPart2(t *testing.T) {
for _, tt := range tests2 {
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
+61
View File
@@ -0,0 +1,61 @@
package main
import (
"fmt"
"strings"
)
func newComputerFromInput(input string) computer {
var instructions []instruction
for _, l := range strings.Split(input, "\n") {
inst := instruction{}
fmt.Sscanf(l, "%s %d", &inst.operation, &inst.argument)
instructions = append(instructions, inst)
}
return computer{instructions: instructions}
}
type computer struct {
instructions []instruction
index int
accumulator int
}
type instruction struct {
operation string
argument int
}
func (c *computer) step() {
switch inst := c.instructions[c.index]; inst.operation {
case "acc":
c.accumulator += inst.argument
c.index++
case "jmp":
c.index += inst.argument
case "nop":
c.index++
default:
panic("unhandled operation type" + inst.operation)
}
}
// func isInfiniteLoop(comp computer) (finalAccumulatorVal int, isLoop bool) {
// ranInstructionsIndices := map[int]bool{}
// for comp.index < len(comp.instructions) {
// nextInst := comp.index
// // is an infinite loop, return out
// if ranInstructionsIndices[nextInst] {
// return 0, true
// }
// ranInstructionsIndices[nextInst] = true
// comp.step()
// }
// // instructions finished, return final accumulator & indicate it was not an
// // infinite loop
// return comp.accumulator, false
// }
+2 -2
View File
@@ -27,7 +27,7 @@ func Test_part1(t *testing.T) {
input string
want int
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -44,7 +44,7 @@ func Test_part2(t *testing.T) {
input string
want int
}{
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {