forked from TrueCloudLab/frostfs-node
[#902] util/locode: Fix parsing minutes
Convert minutes of received coordinates to decimal parts of degree, and do not use decimal part of float as storage for minutes: "5915N 01806E" is 59.25N 18.10E, not 59°15'N 18°06'E. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
2f149f95d4
commit
501c78f327
2 changed files with 80 additions and 11 deletions
51
pkg/util/locode/db/point_test.go
Normal file
51
pkg/util/locode/db/point_test.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package locodedb
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
locodecolumn "github.com/nspcc-dev/neofs-node/pkg/util/locode/column"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPointFromCoordinates(t *testing.T) {
|
||||
testCases := []struct {
|
||||
latGot, longGot string
|
||||
latWant, longWant float64
|
||||
}{
|
||||
{
|
||||
latGot: "5915N",
|
||||
longGot: "01806E",
|
||||
latWant: 59.25,
|
||||
longWant: 18.10,
|
||||
},
|
||||
{
|
||||
latGot: "1000N",
|
||||
longGot: "02030E",
|
||||
latWant: 10.00,
|
||||
longWant: 20.50,
|
||||
},
|
||||
{
|
||||
latGot: "0145S",
|
||||
longGot: "03512W",
|
||||
latWant: -01.75,
|
||||
longWant: -35.20,
|
||||
},
|
||||
}
|
||||
|
||||
var (
|
||||
crd *locodecolumn.Coordinates
|
||||
point *Point
|
||||
err error
|
||||
)
|
||||
|
||||
for _, test := range testCases {
|
||||
crd, err = locodecolumn.CoordinatesFromString(test.latGot + " " + test.longGot)
|
||||
require.NoError(t, err)
|
||||
|
||||
point, err = PointFromCoordinates(crd)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, test.latWant, point.Latitude())
|
||||
require.Equal(t, test.longWant, point.Longitude())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue