github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/geo/geomfn/buffer_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 geomfn
    12  
    13  import (
    14  	"testing"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/geo/geos"
    17  	"github.com/stretchr/testify/require"
    18  )
    19  
    20  func TestParseBufferParams(t *testing.T) {
    21  	testCases := []struct {
    22  		s string
    23  		d float64
    24  
    25  		expected  BufferParams
    26  		expectedD float64
    27  	}{
    28  		{
    29  			s: "",
    30  			d: 100,
    31  			expected: BufferParams{p: geos.BufferParams{
    32  				EndCapStyle:      geos.BufferParamsEndCapStyleRound,
    33  				JoinStyle:        geos.BufferParamsJoinStyleRound,
    34  				SingleSided:      false,
    35  				QuadrantSegments: 8,
    36  				MitreLimit:       5.0,
    37  			}},
    38  			expectedD: 100,
    39  		},
    40  		{
    41  			s: "endcap=flat  join=mitre quad_segs=4",
    42  			d: 100,
    43  			expected: BufferParams{p: geos.BufferParams{
    44  				EndCapStyle:      geos.BufferParamsEndCapStyleFlat,
    45  				JoinStyle:        geos.BufferParamsJoinStyleMitre,
    46  				SingleSided:      false,
    47  				QuadrantSegments: 4,
    48  				MitreLimit:       5.0,
    49  			}},
    50  			expectedD: 100,
    51  		},
    52  		{
    53  			s: "side=left",
    54  			d: 100,
    55  			expected: BufferParams{p: geos.BufferParams{
    56  				EndCapStyle:      geos.BufferParamsEndCapStyleRound,
    57  				JoinStyle:        geos.BufferParamsJoinStyleRound,
    58  				SingleSided:      true,
    59  				QuadrantSegments: 8,
    60  				MitreLimit:       5.0,
    61  			}},
    62  			expectedD: 100,
    63  		},
    64  		{
    65  			s: "side=right",
    66  			d: 100,
    67  			expected: BufferParams{p: geos.BufferParams{
    68  				EndCapStyle:      geos.BufferParamsEndCapStyleRound,
    69  				JoinStyle:        geos.BufferParamsJoinStyleRound,
    70  				SingleSided:      true,
    71  				QuadrantSegments: 8,
    72  				MitreLimit:       5.0,
    73  			}},
    74  			expectedD: -100,
    75  		},
    76  	}
    77  
    78  	for _, tc := range testCases {
    79  		t.Run(tc.s, func(t *testing.T) {
    80  			s, d, err := ParseBufferParams(tc.s, tc.d)
    81  			require.NoError(t, err)
    82  			require.Equal(t, tc.expected, s)
    83  			require.Equal(t, tc.expectedD, d)
    84  		})
    85  	}
    86  }