implemented adjacency and tests
using the new line type am able to check if lines overlap or not.
This commit is contained in:
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user