2023-12-05 12:51:57 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
_ "embed"
|
|
|
|
|
|
|
|
"github.com/matryer/is"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed example.txt
|
|
|
|
var example []byte
|
|
|
|
|
|
|
|
//go:embed input.txt
|
|
|
|
var input []byte
|
|
|
|
|
|
|
|
func TestExample(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
scan := bufio.NewScanner(bytes.NewReader(example))
|
|
|
|
|
2023-12-13 11:30:58 -07:00
|
|
|
r, err := run(scan)
|
|
|
|
is.NoErr(err)
|
|
|
|
is.Equal(r.minLocation, 35)
|
|
|
|
is.Equal(r.minRange, 46)
|
2023-12-05 12:51:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func SkipTestSolution(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
scan := bufio.NewScanner(bytes.NewReader(input))
|
|
|
|
|
2023-12-13 11:30:58 -07:00
|
|
|
r, err := run(scan)
|
|
|
|
is.NoErr(err)
|
|
|
|
is.Equal(r.minLocation, 199602917)
|
|
|
|
is.Equal(r.minRange, 2254686)
|
2023-12-05 12:51:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLookup(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
find := &Lookup{ranges: Ranges{
|
|
|
|
{98, 50, 2},
|
|
|
|
{50, 52, 48},
|
|
|
|
}}
|
|
|
|
is.Equal(find.Find(79), 81)
|
|
|
|
|
|
|
|
find = &Lookup{ranges: Ranges{
|
2023-12-13 11:30:58 -07:00
|
|
|
{77, 45, 23},
|
|
|
|
{45, 81, 19},
|
|
|
|
{64, 68, 13},
|
2023-12-05 12:51:57 -07:00
|
|
|
}}
|
|
|
|
is.Equal(find.Find(77), 45)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFinder(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
find := NewFinder(
|
|
|
|
// seed-to-soil
|
|
|
|
&Lookup{ranges: Ranges{
|
|
|
|
{98, 50, 2},
|
|
|
|
{50, 52, 48},
|
|
|
|
}},
|
|
|
|
// soil-to-fertilizer
|
|
|
|
&Lookup{ranges: Ranges{
|
2023-12-13 11:30:58 -07:00
|
|
|
{15, 0, 37},
|
|
|
|
{52, 37, 2},
|
|
|
|
{0, 39, 15},
|
2023-12-05 12:51:57 -07:00
|
|
|
}},
|
|
|
|
// fertilizer-to-water
|
|
|
|
&Lookup{ranges: Ranges{
|
2023-12-13 11:30:58 -07:00
|
|
|
{53, 49, 8},
|
|
|
|
{11, 0, 42},
|
|
|
|
{0, 42, 7},
|
|
|
|
{7, 57, 4},
|
2023-12-05 12:51:57 -07:00
|
|
|
}},
|
|
|
|
// water-to-light
|
|
|
|
&Lookup{ranges: Ranges{
|
2023-12-13 11:30:58 -07:00
|
|
|
{18, 88, 7},
|
|
|
|
{25, 18, 70},
|
2023-12-05 12:51:57 -07:00
|
|
|
}},
|
|
|
|
// light-to-temperature
|
|
|
|
&Lookup{ranges: Ranges{
|
2023-12-13 11:30:58 -07:00
|
|
|
{77, 45, 23},
|
|
|
|
{45, 81, 19},
|
|
|
|
{64, 68, 13},
|
2023-12-05 12:51:57 -07:00
|
|
|
}},
|
|
|
|
// temperature-to-humidity
|
|
|
|
&Lookup{ranges: Ranges{
|
2023-12-13 11:30:58 -07:00
|
|
|
{69, 0, 1},
|
|
|
|
{0, 1, 69},
|
2023-12-05 12:51:57 -07:00
|
|
|
}},
|
|
|
|
// humidity-to-location
|
|
|
|
&Lookup{ranges: Ranges{
|
2023-12-13 11:30:58 -07:00
|
|
|
{56, 60, 37},
|
|
|
|
{93, 56, 4},
|
2023-12-05 12:51:57 -07:00
|
|
|
}},
|
|
|
|
)
|
|
|
|
is.Equal(find.Find(82), 46)
|
2023-12-13 11:30:58 -07:00
|
|
|
}
|