This commit is contained in:
Gabriel Bizdoc 2025-12-13 22:57:12 +02:00
parent 4b8bf419e2
commit 796a7a1b4f
No known key found for this signature in database
GPG Key ID: 3F0EDAECA5BE9ED9
2 changed files with 64 additions and 0 deletions

8
.gitignore vendored
View File

@ -1 +1,9 @@
/problems
tmp
# Ignore these to avoid leaking local replacements to the devkit
./go.mod
./go.sum
go.mod
go.sum

56
tests/tests.go Normal file
View File

@ -0,0 +1,56 @@
package tests
import (
"fmt"
"os"
"testing"
"time"
"git.bizdoc.ro/gabi-public/Advent-of-Code.git/aoc"
)
func assert(t *testing.T, err error, a, b any) {
t.Helper()
if err != nil {
t.Error(err)
}
want := fmt.Sprintf("%v", a)
got := fmt.Sprintf("%v", b)
if got != want {
err = fmt.Errorf("want %s, got %s", want, got)
t.Error(err)
}
}
func Handler[T any](f func(ctx aoc.Context) (T, error)) func(ctx aoc.Context) (any, error) {
return func(c aoc.Context) (any, error) {
return f(c)
}
}
func Handler2[T any, K any](param T, f func(ctx aoc.Context, param T) (K, error)) func(ctx aoc.Context) (any, error) {
return func(c aoc.Context) (any, error) {
return f(c, param)
}
}
func Test(t *testing.T, file string, handler func(aoc.Context) (any, error), want any) {
t.Helper()
f, err := os.Open("tmp/" + file)
if err != nil {
panic(err)
}
defer f.Close()
start := time.Now()
got, err := handler(aoc.Context{
Body: f,
Logger: nil,
Context: nil,
})
t.Log("took", time.Since(start))
assert(t, err, want, got)
}