package area import "testing" func TestValidateGeometry(t *testing.T) { tests := []struct { name, kind, direction string points []Point valid bool }{{"polygon", KindPolygon, "", []Point{{.1, .1}, {.9, .1}, {.5, .8}}, true}, {"self intersection", KindPolygon, "", []Point{{.1, .1}, {.9, .9}, {.9, .1}, {.1, .9}}, false}, {"outside", KindPolygon, "", []Point{{-.1, .1}, {.9, .1}, {.5, .8}}, false}, {"line", KindLine, DirectionAToB, []Point{{.1, .1}, {.9, .9}}, true}, {"line direction", KindLine, "", []Point{{.1, .1}, {.9, .9}}, false}, {"line degenerate", KindLine, DirectionBoth, []Point{{.1, .1}, {.1, .1}}, 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("err=%v valid=%v", err, test.valid) } }) } }