mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-01 09:48:27 +02:00
cleanup tests
updated 2020 templates for easier addition of tests
This commit is contained in:
@@ -17,24 +17,46 @@ type TemplateData struct {
|
||||
|
||||
var testTemplateString = `package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/alexchao26/advent-of-code-go/util"
|
||||
)
|
||||
import "testing"
|
||||
|
||||
var tests1 = []struct {
|
||||
name string
|
||||
want int
|
||||
input string
|
||||
// add extra args if needed
|
||||
}{
|
||||
// {"actual", /* ACTUAL ANSWER */, util.ReadFile("input.txt")},
|
||||
}
|
||||
|
||||
func TestPart1(t *testing.T) {
|
||||
// Examples
|
||||
|
||||
// Run actual problem input
|
||||
// part1(util.ReadFile("input.txt"))
|
||||
for _, test := range tests1 {
|
||||
t.Run(test.name, func(*testing.T) {
|
||||
got := part1(test.input)
|
||||
if got != test.want {
|
||||
t.Errorf("want %v, got %v", test.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var tests2 = []struct {
|
||||
name string
|
||||
want int
|
||||
input string
|
||||
// add extra args if needed
|
||||
}{
|
||||
// {"actual", /* ACTUAL ANSWER */, util.ReadFile("input.txt")},
|
||||
}
|
||||
|
||||
func TestPart2(t *testing.T) {
|
||||
// Examples
|
||||
|
||||
// Run actual problem input
|
||||
// part2(util.ReadFile("input.txt"))
|
||||
for _, test := range tests2 {
|
||||
t.Run(test.name, func(*testing.T) {
|
||||
got := part2(test.input)
|
||||
if got != test.want {
|
||||
t.Errorf("want %v, got %v", test.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
@@ -104,6 +126,7 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// note: data is no longer used, but keeping it for future reference of text/template
|
||||
solutionTemp.Execute(solutionWriter, data)
|
||||
testTemp.Execute(testWriter, data)
|
||||
fmt.Println("templates made")
|
||||
|
||||
Reference in New Issue
Block a user