1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-12-26 05:51:20 +00:00
go_helpers/position/haversine_test.go

31 lines
760 B
Go
Raw Normal View History

2016-05-06 21:43:45 +00:00
package position_test
import (
"testing"
2016-05-06 21:43:45 +00:00
. "github.com/Luzifer/go_helpers/v2/position"
"github.com/stretchr/testify/assert"
2016-05-06 21:43:45 +00:00
)
func TestHaversine(t *testing.T) {
testCases := []struct {
2016-05-06 21:43:45 +00:00
SourceLat float64
SourceLon float64
DestLat float64
DestLon float64
Distance float64
}{
{50.066389, -5.714722, 58.643889, -3.070000, 968.8535441168448},
{50.063995, -5.609464, 53.553027, 9.993782, 1137.894906816002},
{53.553027, 9.993782, 53.554528, 9.991357, 0.23133816528015647},
{50, 9, 51, 9, 111.19492664455873},
{0, 9, 0, 10, 111.19492664455873},
{1, 0, -1, 0, 222.38985328911747},
}
for i := range testCases {
tc := testCases[i]
assert.Equal(t, tc.Distance, Haversine(tc.SourceLon, tc.SourceLat, tc.DestLon, tc.DestLat))
}
}