diff --git a/point_test.go b/point_test.go index 954c82f..c8f384b 100644 --- a/point_test.go +++ b/point_test.go @@ -62,7 +62,7 @@ func TestLineIntersection(t *testing.T) { {[]line{line{Point{5, 8}, Point{8, 5}}, line{Point{3, 7}, Point{7, 3}}}, Point{0, 0}}, } for _, rt := range lineIntersectionTest { - actual := lineIntersection(rt.l[0], rt.l[1]) + actual, _ := lineIntersection(rt.l[0], rt.l[1]) if actual != rt.expected { t.Errorf( "failed spiral:\n\texpected: %f\n\t actual: %f", diff --git a/rectangle_test.go b/rectangle_test.go index 84d6e89..6e66eb6 100644 --- a/rectangle_test.go +++ b/rectangle_test.go @@ -97,7 +97,7 @@ func TestContainment(t *testing.T) { } func TestAdjacency(t *testing.T) { - var adjacencyTest = []struct { + var adjacencyTests = []struct { r []Rectangle expected bool }{ @@ -132,7 +132,7 @@ func TestAdjacency(t *testing.T) { true, }, } - for _, rt := range adjacencyTest { + for _, rt := range adjacencyTests { actual := Adjacency(rt.r[0], rt.r[1]) if actual != rt.expected { t.Errorf( @@ -144,3 +144,50 @@ func TestAdjacency(t *testing.T) { } } + +func TestIntersection(t *testing.T) { + var intersectionTests = []struct { + r []Rectangle + expected []Point + }{ + { + []Rectangle{ + Rectangle{Point{0, 0}, Point{0, 3}, Point{3, 0}, Point{3, 3}}, + Rectangle{Point{2, 1}, Point{2, 2}, Point{4, 1}, Point{4, 2}}}, + []Point{Point{3, 1}, Point{3, 2}}, + }, + { + []Rectangle{ + Rectangle{Point{0, 0}, Point{0, 3}, Point{3, 0}, Point{3, 3}}, + Rectangle{Point{0, 0}, Point{0, -1}, Point{-1, 0}, Point{-1, -1}}}, + []Point{Point{0, 0}, Point{0, 0}}, + }, + { + []Rectangle{ + Rectangle{Point{2, 1}, Point{2, 2}, Point{4, 1}, Point{4, 2}}, + Rectangle{Point{0, 0}, Point{0, -1}, Point{-1, 0}, Point{-1, -1}}}, + []Point{}, + }, + } + for _, rt := range intersectionTests { + actual := Intersection(rt.r[0], rt.r[1]) + if len(actual) != len(rt.expected) { + t.Errorf( + "failed spiral:\n\texpected: %d\n\t actual: %d", + len(rt.expected), + len(actual), + ) + continue + } + for i, _ := range actual { + if actual[i] != rt.expected[i] { + t.Errorf( + "failed spiral:\n\texpected: %d\n\t actual: %d", + rt.expected[i], + actual[i], + ) + } + } + + } +}