72 lines
1.7 KiB
Go
72 lines
1.7 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 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)
|
|
}
|