Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geo: move TestClipRectByEWKT test to geoindex #49920

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions pkg/geo/geo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import (
"testing"

"github.com/cockroachdb/cockroach/pkg/geo/geopb"
"github.com/cockroachdb/cockroach/pkg/geo/geos"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/datadriven"
"github.com/golang/geo/s2"
"github.com/stretchr/testify/require"
"github.com/twpayne/go-geom"
Expand Down Expand Up @@ -474,42 +471,3 @@ func TestGeographyAsS2(t *testing.T) {
})
}
}

func TestClipEWKBByRect(t *testing.T) {
defer leaktest.AfterTest(t)()

var g *Geometry
var err error
datadriven.RunTest(t, "testdata/clip", func(t *testing.T, d *datadriven.TestData) string {
switch d.Cmd {
case "geometry":
g, err = ParseGeometry(d.Input)
if err != nil {
return err.Error()
}
return ""
case "clip":
var xMin, yMin, xMax, yMax int
d.ScanArgs(t, "xmin", &xMin)
d.ScanArgs(t, "ymin", &yMin)
d.ScanArgs(t, "xmax", &xMax)
d.ScanArgs(t, "ymax", &yMax)
ewkb, err := geos.ClipEWKBByRect(
g.EWKB(), float64(xMin), float64(yMin), float64(xMax), float64(yMax))
if err != nil {
return err.Error()
}
// TODO(sumeer):
// - add WKB to WKT and print exact output
// - expand test with more inputs
return fmt.Sprintf(
"%d => %d (srid: %d)",
len(g.EWKB()),
len(ewkb),
g.SRID(),
)
default:
return fmt.Sprintf("unknown command: %s", d.Cmd)
}
})
}
40 changes: 40 additions & 0 deletions pkg/geo/geoindex/s2_geometry_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"testing"

"github.com/cockroachdb/cockroach/pkg/geo"
"github.com/cockroachdb/cockroach/pkg/geo/geos"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/datadriven"
)
Expand Down Expand Up @@ -65,3 +66,42 @@ func TestS2GeometryIndexBasic(t *testing.T) {
}
})
}

func TestClipEWKBByRect(t *testing.T) {
defer leaktest.AfterTest(t)()

var g *geo.Geometry
var err error
datadriven.RunTest(t, "testdata/clip", func(t *testing.T, d *datadriven.TestData) string {
switch d.Cmd {
case "geometry":
g, err = geo.ParseGeometry(d.Input)
if err != nil {
return err.Error()
}
return ""
case "clip":
var xMin, yMin, xMax, yMax int
d.ScanArgs(t, "xmin", &xMin)
d.ScanArgs(t, "ymin", &yMin)
d.ScanArgs(t, "xmax", &xMax)
d.ScanArgs(t, "ymax", &yMax)
ewkb, err := geos.ClipEWKBByRect(
g.EWKB(), float64(xMin), float64(yMin), float64(xMax), float64(yMax))
if err != nil {
return err.Error()
}
// TODO(sumeer):
// - add WKB to WKT and print exact output
// - expand test with more inputs
return fmt.Sprintf(
"%d => %d (srid: %d)",
len(g.EWKB()),
len(ewkb),
g.SRID(),
)
default:
return fmt.Sprintf("unknown command: %s", d.Cmd)
}
})
}
File renamed without changes.