45 lines
849 B
Go
45 lines
849 B
Go
package day6_test
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"source.toby3d.me/toby3d/adventofcode/internal/day6/part1"
|
|
"source.toby3d.me/toby3d/adventofcode/internal/day6/part2"
|
|
)
|
|
|
|
var input []byte
|
|
|
|
func TestMain(m *testing.M) {
|
|
var err error
|
|
if input, err = os.ReadFile(filepath.Join("testdata", "input")); err != nil {
|
|
log.Fatalln("cannot open input file:", err)
|
|
}
|
|
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func ExampleDay6() {
|
|
races, err := part1.ParseDocument(bytes.NewReader(input))
|
|
if err != nil {
|
|
log.Fatalln("cannot parse races document:", err)
|
|
}
|
|
|
|
fmt.Println(races.Power())
|
|
// Output: 505494
|
|
}
|
|
|
|
func ExampleDay6_PartTwo() {
|
|
race, err := part2.ParseDocument(bytes.NewReader(input))
|
|
if err != nil {
|
|
log.Fatalln("cannot parse race document:", err)
|
|
}
|
|
|
|
fmt.Println(race.CountWinningStrategies())
|
|
// Output: 23632299
|
|
}
|