85 lines
2.1 KiB
Go
85 lines
2.1 KiB
Go
package day24
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadLine(t *testing.T) {
|
|
lines := `19, 13, 30 @ -2, 1, -2
|
|
18, 19, 22 @ -1, -1, -2
|
|
20, 25, 34 @ -2, -2, -4
|
|
12, 31, 28 @ -1, -2, -1
|
|
20, 19, 15 @ 1, -5, -3`
|
|
|
|
for _, line := range strings.Split(lines, "\n") {
|
|
hail := ReadHailLine(line)
|
|
t.Log(hail)
|
|
}
|
|
|
|
}
|
|
|
|
func TestReadLineInput(t *testing.T) {
|
|
lines := `147847636573416, 190826994408605, 140130741291716 @ 185, 49, 219
|
|
287509258905812, 207449079739538, 280539021150559 @ -26, 31, 8
|
|
390970075767404, 535711685410735, 404166182422876 @ -147, -453, -149
|
|
306391780523937, 382508967958270, 264612201472049 @ -24, -274, 28
|
|
278063616684570, 510959526404728, 288141792965603 @ -18, -441, -6`
|
|
for _, line := range strings.Split(lines, "\n") {
|
|
hail := ReadHailLine(line)
|
|
t.Logf("%+v\n", hail)
|
|
}
|
|
|
|
}
|
|
|
|
func TestSecondPointIsInFuture(t *testing.T) {
|
|
lines := `19, 13, 30 @ -2, 1, -2
|
|
18, 19, 22 @ -1, -1, -2
|
|
20, 25, 34 @ -2, -2, -4
|
|
12, 31, 28 @ -1, -2, -1
|
|
20, 19, 15 @ 1, -5, -3`
|
|
|
|
for _, line := range strings.Split(lines, "\n") {
|
|
hail := ReadHailLine(line)
|
|
t.Log(hail)
|
|
t.Logf("calced seconds point %+v is in future %t\n", hail.p1, hail.PointInFuture(hail.p1))
|
|
}
|
|
|
|
}
|
|
|
|
func TestIntersectExampleOne(t *testing.T) {
|
|
// Hailstone A: 19, 13, 30 @ -2, 1, -2
|
|
// Hailstone B: 18, 19, 22 @ -1, -1, -2
|
|
// Hailstones' paths will cross inside the test area (at x=14.333, y=15.333).
|
|
|
|
hA := ReadHailLine("19, 13, 30 @ -2, 1, -2")
|
|
hB := ReadHailLine("18, 19, 22 @ -1, -1, -2")
|
|
|
|
x, y, check := IntersectByTwoPoints(hA, hB)
|
|
if !check {
|
|
panic("should intersect")
|
|
}
|
|
t.Logf("got intersection at %f %f", x, y)
|
|
}
|
|
|
|
func TestIntersectExampleTwo(t *testing.T) {
|
|
// Hailstone A: 18, 19, 22 @ -1, -1, -2
|
|
// Hailstone B: 20, 25, 34 @ -2, -2, -4
|
|
hA := ReadHailLine("18, 19, 22 @ -1, -1, -2")
|
|
hB := ReadHailLine("20, 25, 34 @ -2, -2, -4")
|
|
|
|
x, y, check := IntersectByTwoPoints(hA, hB)
|
|
if check {
|
|
panic("should not intersect")
|
|
}
|
|
t.Logf("got intersection at %f %f", x, y)
|
|
}
|
|
|
|
func TestExamplePairwiseChecks(t *testing.T) {
|
|
filename := "example"
|
|
hails := ReadHailFile(filename)
|
|
|
|
intersections := CheckPairwiseIntersections(hails)
|
|
t.Log("counted intersections ", intersections)
|
|
}
|