implemented adjacency and tests

using the new line type am able to check if lines overlap or not.
This commit is contained in:
dm
2016-08-26 16:27:47 -07:00
parent d6e76ef26b
commit aaf2dbb2eb
2 changed files with 92 additions and 2 deletions
+49
View File
@@ -95,3 +95,52 @@ func TestContainment(t *testing.T) {
}
}
func TestAdjacency(t *testing.T) {
var adjacencyTest = []struct {
r []Rectangle
expected bool
}{
{
[]Rectangle{
Rectangle{Point{0, 0}, Point{0, 3}, Point{3, 0}, Point{3, 3}},
Rectangle{Point{2, 2}, Point{2, 3}, Point{3, 2}, Point{3, 3}}},
true,
},
{
[]Rectangle{
Rectangle{Point{0, 0}, Point{0, 3}, Point{3, 0}, Point{3, 3}},
Rectangle{Point{1, 3}, Point{2, 3}, Point{1, 4}, Point{2, 4}}},
true,
},
{
[]Rectangle{
Rectangle{Point{2, 2}, Point{2, 3}, Point{3, 2}, Point{3, 3}},
Rectangle{Point{1, 3}, Point{2, 3}, Point{1, 4}, Point{2, 4}}},
false,
},
{
[]Rectangle{
Rectangle{Point{-2, -2}, Point{-2, -3}, Point{-3, -2}, Point{-3, -3}},
Rectangle{Point{-1, -3}, Point{-2, -3}, Point{-1, -4}, Point{-2, -4}}},
false,
},
{
[]Rectangle{
Rectangle{Point{0, 0}, Point{0, -3}, Point{-3, 0}, Point{-3, -3}},
Rectangle{Point{-2, -2}, Point{-2, -3}, Point{-3, -2}, Point{-3, -3}}},
true,
},
}
for _, rt := range adjacencyTest {
actual := Adjacency(rt.r[0], rt.r[1])
if actual != rt.expected {
t.Errorf(
"failed spiral:\n\texpected: %d\n\t actual: %d",
rt.expected,
actual,
)
}
}
}