Skip to content
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
1 change: 1 addition & 0 deletions pkg/geo/geomfn/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ go_test(
"//pkg/geo/geopb",
"//pkg/geo/geos",
"//pkg/geo/geotest",
"//pkg/testutils/floatcmp",
"@com_github_cockroachdb_errors//:errors",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
Expand Down
23 changes: 21 additions & 2 deletions pkg/geo/geomfn/angle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,32 @@ package geomfn
import (
"fmt"
"math"
"runtime"
"strconv"
"testing"

"github.com/cockroachdb/cockroach/pkg/geo"
"github.com/cockroachdb/cockroach/pkg/geo/geopb"
"github.com/cockroachdb/cockroach/pkg/testutils/floatcmp"
"github.com/stretchr/testify/require"
)

func assertFloatsMatch(t *testing.T, expected, actual float64) {
if runtime.GOARCH != "s390x" {
require.Equal(t, expected, actual)
return
}
// s390x system has architecture support for 'atan' function (which is used
// in 'angleFromCoords') and produces slightly different result than math
// operations we do to get the expected number. To go around this, we use
// the custom float comparison that checks 15 significant decimal digits.
exp := strconv.FormatFloat(expected, 'f', -1, 64)
act := strconv.FormatFloat(actual, 'f', -1, 64)
matched, err := floatcmp.FloatsMatch(exp, act)
require.NoError(t, err)
require.True(t, matched)
}

func TestAngle(t *testing.T) {
pf := func(f float64) *float64 {
return &f
Expand Down Expand Up @@ -58,7 +77,7 @@ func TestAngle(t *testing.T) {
angle, err := Angle(g1, g2, g3, g4)
require.NoError(t, err)
if tc.expected != nil && angle != nil {
require.Equal(t, *tc.expected, *angle)
assertFloatsMatch(t, *tc.expected, *angle)
} else {
require.Equal(t, tc.expected, angle)
}
Expand Down Expand Up @@ -134,7 +153,7 @@ func TestAngleLineString(t *testing.T) {
angle, err := AngleLineString(g1, g2)
require.NoError(t, err)
if tc.expected != nil && angle != nil {
require.Equal(t, *tc.expected, *angle)
assertFloatsMatch(t, *tc.expected, *angle)
} else {
require.Equal(t, tc.expected, angle)
}
Expand Down