determine size of rectangle
To determine the size of rectangle, it was required to be able to determine who would be the neighboring points. A neighbor is a point that would make the exterior of the rectangle, not the cross-section. Finding the neighbors allows for a simple l*w to calculate size.
This commit is contained in:
@@ -27,3 +27,28 @@ func TestIsRect(t *testing.T) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestSize(t *testing.T) {
|
||||
var isRectTests = []struct {
|
||||
r Rectangle
|
||||
expected float64
|
||||
}{
|
||||
{Rectangle{P1: Point{1, 1}, P2: Point{1, 2}, P3: Point{2, 1}, P4: Point{2, 2}}, 1},
|
||||
{Rectangle{P1: Point{0, 0}, P2: Point{0, 1}, P3: Point{1, 0}, P4: Point{1, 1}}, 1},
|
||||
{Rectangle{P1: Point{0, 0}, P2: Point{0, -1}, P3: Point{-1, 0}, P4: Point{-1, -1}}, 1},
|
||||
{Rectangle{P1: Point{1.5, 1.5}, P2: Point{1.5, 3.5}, P3: Point{3.5, 1.5}, P4: Point{3.5, 3.5}}, 4},
|
||||
{Rectangle{P1: Point{0, 0}, P2: Point{0, 3}, P3: Point{2, 0}, P4: Point{2, 3}}, 6},
|
||||
{Rectangle{P1: Point{0, 0}, P2: Point{0, 100}, P3: Point{100, 0}, P4: Point{100, 100}}, 10000},
|
||||
}
|
||||
for _, rt := range isRectTests {
|
||||
actual := rt.r.Size()
|
||||
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