github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/geo/bbox_test.go (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package geo
    12  
    13  import (
    14  	"fmt"
    15  	"testing"
    16  
    17  	"github.com/cockroachdb/cockroach/pkg/geo/geopb"
    18  	"github.com/stretchr/testify/require"
    19  	"github.com/twpayne/go-geom"
    20  )
    21  
    22  func TestBoundingBoxFromGeom(t *testing.T) {
    23  	testCases := []struct {
    24  		g        geom.T
    25  		expected *geopb.BoundingBox
    26  	}{
    27  		{testGeomPoint, &geopb.BoundingBox{MinX: 1, MaxX: 1, MinY: 2, MaxY: 2}},
    28  		{testGeomLineString, &geopb.BoundingBox{MinX: 1, MaxX: 2, MinY: 1, MaxY: 2}},
    29  		{testGeomPolygon, &geopb.BoundingBox{MinX: 1, MaxX: 2, MinY: 1, MaxY: 2}},
    30  		{testGeomMultiPoint, &geopb.BoundingBox{MinX: 1, MaxX: 2, MinY: 1, MaxY: 2}},
    31  		{testGeomMultiLineString, &geopb.BoundingBox{MinX: 1, MaxX: 4, MinY: 1, MaxY: 4}},
    32  		{testGeomMultiPolygon, &geopb.BoundingBox{MinX: 1, MaxX: 4, MinY: 1, MaxY: 4}},
    33  		{testGeomGeometryCollection, &geopb.BoundingBox{MinX: 1, MaxX: 2, MinY: 1, MaxY: 2}},
    34  		{emptyGeomPoint, nil},
    35  		{emptyGeomLineString, nil},
    36  		{emptyGeomPolygon, nil},
    37  		{emptyGeomMultiPoint, nil},
    38  		{emptyGeomMultiLineString, nil},
    39  		{emptyGeomMultiPolygon, nil},
    40  		{emptyGeomGeometryCollection, nil},
    41  		{emptyGeomPointInGeometryCollection, &geopb.BoundingBox{MinX: 1, MaxX: 2, MinY: 1, MaxY: 2}},
    42  		{emptyGeomObjectsInGeometryCollection, nil},
    43  	}
    44  
    45  	for _, tc := range testCases {
    46  		t.Run(fmt.Sprintf("%#v", tc.g), func(t *testing.T) {
    47  			bbox, err := BoundingBoxFromGeom(tc.g)
    48  			require.NoError(t, err)
    49  			require.Equal(t, tc.expected, bbox)
    50  		})
    51  	}
    52  }