github.com/dolthub/go-mysql-server@v0.18.0/sql/expression/function/spatial/multipolygon_test.go (about) 1 // Copyright 2020-2022 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package spatial 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 22 "github.com/dolthub/go-mysql-server/sql" 23 "github.com/dolthub/go-mysql-server/sql/expression" 24 "github.com/dolthub/go-mysql-server/sql/types" 25 ) 26 27 func TestMultiPolygon(t *testing.T) { 28 t.Run("create valid multipolygon", func(t *testing.T) { 29 require := require.New(t) 30 line := types.LineString{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: 0}}} 31 poly := types.Polygon{Lines: []types.LineString{line}} 32 f, err := NewMultiPolygon(expression.NewLiteral(poly, types.PolygonType{})) 33 require.NoError(err) 34 35 v, err := f.Eval(sql.NewEmptyContext(), nil) 36 require.NoError(err) 37 require.Equal(types.MultiPolygon{Polygons: []types.Polygon{poly}}, v) 38 }) 39 40 t.Run("create valid multipolygon with multiple polygons", func(t *testing.T) { 41 require := require.New(t) 42 line1 := types.LineString{Points: []types.Point{{X: 0, Y: 0}, {X: 1, Y: 0}, {X: 1, Y: 1}, {X: 0, Y: 0}}} 43 poly1 := types.Polygon{Lines: []types.LineString{line1}} 44 line2 := types.LineString{Points: []types.Point{{X: 0, Y: 0}, {X: 0, Y: 1}, {X: 1, Y: 1}, {X: 0, Y: 0}}} 45 poly2 := types.Polygon{Lines: []types.LineString{line2}} 46 f, err := NewMultiPolygon( 47 expression.NewLiteral(poly1, types.PolygonType{}), 48 expression.NewLiteral(poly2, types.PolygonType{}), 49 ) 50 require.NoError(err) 51 52 v, err := f.Eval(sql.NewEmptyContext(), nil) 53 require.NoError(err) 54 require.Equal(types.MultiPolygon{Polygons: []types.Polygon{poly1, poly2}}, v) 55 }) 56 } 57 58 func TestNewMultiPolygon(t *testing.T) { 59 require := require.New(t) 60 _, err := NewMultiPolygon(expression.NewLiteral(nil, types.PolygonType{}), 61 expression.NewLiteral(nil, types.PolygonType{}), 62 expression.NewLiteral(nil, types.PolygonType{}), 63 ) 64 require.NoError(err) 65 }