2020-05-14 11:57:26 +02:00
|
|
|
package meta
|
|
|
|
|
2020-07-08 10:03:59 +02:00
|
|
|
import (
|
|
|
|
"testing"
|
2020-11-21 18:08:41 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-07-08 10:03:59 +02:00
|
|
|
)
|
2020-05-14 11:57:26 +02:00
|
|
|
|
|
|
|
func TestGpsToLat(t *testing.T) {
|
|
|
|
lat := GpsToDecimal("51 deg 15' 17.47\" N")
|
2022-12-28 20:12:30 +01:00
|
|
|
exp := 51.254852
|
2020-05-14 11:57:26 +02:00
|
|
|
|
2022-12-28 20:12:30 +01:00
|
|
|
assert.InEpsilon(t, lat, exp, 0.1)
|
2020-05-14 11:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGpsToLng(t *testing.T) {
|
|
|
|
lng := GpsToDecimal("7 deg 23' 22.09\" E")
|
2022-12-28 20:12:30 +01:00
|
|
|
exp := 7.389470
|
2020-05-14 11:57:26 +02:00
|
|
|
|
2022-12-28 20:12:30 +01:00
|
|
|
assert.InEpsilon(t, lng, exp, 0.1)
|
2020-05-14 11:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGpsToLatLng(t *testing.T) {
|
2020-07-08 10:03:59 +02:00
|
|
|
t.Run("valid string", func(t *testing.T) {
|
|
|
|
lat, lng := GpsToLatLng("51 deg 15' 17.47\" N, 7 deg 23' 22.09\" E")
|
2022-12-28 20:12:30 +01:00
|
|
|
expLat, expLng := 51.254852, 7.389470
|
2020-05-14 11:57:26 +02:00
|
|
|
|
2022-12-28 20:12:30 +01:00
|
|
|
assert.InEpsilon(t, lat, expLat, 0.1)
|
|
|
|
assert.InEpsilon(t, lng, expLng, 0.1)
|
2020-07-08 10:03:59 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty string", func(t *testing.T) {
|
|
|
|
lat, lng := GpsToLatLng("")
|
2022-12-28 20:12:30 +01:00
|
|
|
assert.Equal(t, float64(0), lat)
|
|
|
|
assert.Equal(t, float64(0), lng)
|
2020-07-08 10:03:59 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid string", func(t *testing.T) {
|
|
|
|
lat, lng := GpsToLatLng("abc bdf")
|
2022-12-28 20:12:30 +01:00
|
|
|
assert.Equal(t, float64(0), lat)
|
|
|
|
assert.Equal(t, float64(0), lng)
|
2020-07-08 10:03:59 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGpsToDecimal(t *testing.T) {
|
|
|
|
t.Run("valid string", func(t *testing.T) {
|
|
|
|
r := GpsToDecimal("51 deg 15' 17.47\" N")
|
2022-12-28 20:12:30 +01:00
|
|
|
assert.InEpsilon(t, 51.25485277777778, r, 0.01)
|
2020-07-08 10:03:59 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty string", func(t *testing.T) {
|
|
|
|
r := GpsToDecimal("")
|
2022-12-28 20:12:30 +01:00
|
|
|
assert.Equal(t, float64(0), r)
|
2020-07-08 10:03:59 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid string", func(t *testing.T) {
|
|
|
|
r := GpsToDecimal("abc")
|
2022-12-28 20:12:30 +01:00
|
|
|
assert.Equal(t, float64(0), r)
|
2020-07-08 10:03:59 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGpsCoord(t *testing.T) {
|
|
|
|
t.Run("valid string", func(t *testing.T) {
|
2022-04-14 10:49:56 +02:00
|
|
|
r := ParseFloat("51")
|
2020-07-08 10:03:59 +02:00
|
|
|
assert.Equal(t, float64(51), r)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty string", func(t *testing.T) {
|
2022-04-14 10:49:56 +02:00
|
|
|
r := ParseFloat("")
|
2020-07-08 10:03:59 +02:00
|
|
|
assert.Equal(t, float64(0), r)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid string", func(t *testing.T) {
|
2022-04-14 10:49:56 +02:00
|
|
|
r := ParseFloat("abc")
|
2020-07-08 10:03:59 +02:00
|
|
|
assert.Equal(t, float64(0), r)
|
|
|
|
})
|
2020-05-14 11:57:26 +02:00
|
|
|
}
|