runner

package
v0.0.0-...-5d524ee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	context.Context // base context
	// contains filtered or unexported fields
}

Context is the runner

func (*Context) Ctx

func (c *Context) Ctx() context.Context

func (*Context) Day

func (c *Context) Day() int

func (*Context) OutputFile

func (c *Context) OutputFile(ext string) string

OutputFile returns the path to the output file for this day and part

func (*Context) SaveOutput

func (c *Context) SaveOutput() bool

SaveOutput returns true if the output should be saved to a file

type Day

type Day[Input, Cache any] struct {
	// contains filtered or unexported fields
}

Day represents a day of the advent of code

func NewDay

func NewDay[Input any](day int, parser func([]byte) (Input, error), part1, part2 Part[Input]) *Day[Input, Input]

NewDay returns a day which is parsed as a whole initially, and then the parsed data is given to each part.

See NewStreamingDay for a stream processing version

func NewStreamingDay

func NewStreamingDay[Input any](day int, parser func([]byte) stream.Stream[Input], part1, part2 Part[stream.Stream[Input]]) *Day[stream.Stream[Input], []Input]

NewStreamingDay creates a day which takes a parser to convert the input bytes into a stream of inputs, which the part 1 and part 2 functions can then use.

func (*Day[Input, Cache]) Day

func (d *Day[Input, Cache]) Day() int

func (*Day[Input, Cache]) Run

func (d *Day[Input, Cache]) Run(ctx context.Context, saveOutput bool)

Run executes the given parts with the given input

If an error is encountered, the program will exit with a non-zero exit code

func (*Day[Input, Cache]) Test

func (d *Day[Input, Cache]) Test(t *testing.T, part1TestInput string, part1ExpectedAnswer int, part2estInput string, part2ExpectedAnswer int)

Test runs the given parts with the given input and asserts the answers

func (*Day[Input, Cache]) TestContext

func (d *Day[Input, Cache]) TestContext(t *testing.T, partNum int) *Context

TestContext creates a context for testing with

func (*Day[Input, Cache]) TestPart1

func (d *Day[Input, Cache]) TestPart1(t *testing.T, input string, expectedAnswer int)

TestPart1 runs the given part 1 with the given input and asserts the answer

func (*Day[Input, Cache]) TestPart2

func (d *Day[Input, Cache]) TestPart2(t *testing.T, input string, expectedAnswer int)

TestPart2 runs the given part 2 with the given input and asserts the answer

func (*Day[Input, Cache]) WithExpectedAnswers

func (d *Day[Input, Cache]) WithExpectedAnswers(part1, part2 int) *Day[Input, Cache]

func (*Day[Input, Cache]) WithPart1KnownMax

func (d *Day[Input, Cache]) WithPart1KnownMax(max int) *Day[Input, Cache]

func (*Day[Input, Cache]) WithPart2KnownMax

func (d *Day[Input, Cache]) WithPart2KnownMax(max int) *Day[Input, Cache]

type Part

type Part[Input any] func(ctx *Context, log zerolog.Logger, input Input) (answer int, err error)

Part represents a function which given the input will return the answer for that part of the day

type RunnableDay

type RunnableDay interface {
	// Day returns the day number
	Day() int

	// Run runs the day
	Run(ctx context.Context, saveOutput bool)
}

func AllDays

func AllDays() []RunnableDay

AllDays returns all the days in order

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL