28 lines
889 B
Go
28 lines
889 B
Go
package area
|
|
|
|
import "testing"
|
|
|
|
func TestGeometryValidation(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
kind string
|
|
direction string
|
|
points []Point
|
|
valid bool
|
|
}{
|
|
{"polygon", KindPolygon, "", []Point{{0.1, 0.1}, {0.8, 0.1}, {0.5, 0.8}}, true},
|
|
{"self intersecting", KindPolygon, "", []Point{{0.1, 0.1}, {0.8, 0.8}, {0.8, 0.1}, {0.1, 0.8}}, false},
|
|
{"outside", KindPolygon, "", []Point{{-0.1, 0.1}, {0.8, 0.1}, {0.5, 0.8}}, false},
|
|
{"line", KindDirectionLine, DirectionForward, []Point{{0.2, 0.5}, {0.8, 0.5}}, true},
|
|
{"line missing direction", KindDirectionLine, "", []Point{{0.2, 0.5}, {0.8, 0.5}}, false},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
err := validateGeometry(test.kind, test.direction, test.points)
|
|
if (err == nil) != test.valid {
|
|
t.Fatalf("valid=%v err=%v", test.valid, err)
|
|
}
|
|
})
|
|
}
|
|
}
|