Skip to content

Commit 257b60a

Browse files
committed
Fix up test
1 parent 49cc90f commit 257b60a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

geo/haversine_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
package geo
1+
package geo
22

3-
import "testing"
3+
import (
4+
"fmt"
5+
"testing"
6+
)
47

5-
func TestHaverine(t *testing.T) {
6-
//distance b/w lyon and paris
7-
if got, want := 391.970466; Haversine(45.7597, 4.8422, 48.8567, 2.3508) != want {
8-
t.Errorf("Havesine = %f; want %f", got, want)
8+
func check(t* testing.T, want string, lat1, lon1, lat2, lon2 float64) {
9+
if got := fmt.Sprintf("%.2f", Haversine(lat1, lon1, lat2, lon2)); got != want {
10+
t.Errorf("Haversine = got %f; want %f", got, want)
911
}
1012

11-
if got, want := 2884.632202; Haversine(36.12, -86.67, 33.94, -118.40) != want {
12-
t.Errorf("Havesine = %f; want %f", got, want)
13-
}
13+
}
1414

15+
func TestHaverine(t *testing.T) {
16+
//distance b/w lyon and paris
17+
check(t, "391.97", 45.7597, 4.8422, 48.8567, 2.3508)
18+
check(t, "2884.63", 36.12, -86.67, 33.94, -118.40)
1519
}

0 commit comments

Comments
 (0)