-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
85 lines (71 loc) · 1.8 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"testing"
)
func TestDistance(t *testing.T) {
var lat1 float64 = 50.72
var lon1 float64 = -113.99
var lat2 float64 = 51.72
var lon2 float64 = -115.99
distance := distance(lat1, lon1, lat2, lon2)
if distance != 178218.93191668583 {
t.Errorf("Distance was incorrect. Expected: 178.21893191668582")
}
}
func TestRelativeAngle(t *testing.T) {
var lat1 float64 = 50.72
var lon1 float64 = -113.99
var lat2 float64 = 51.72
var lon2 float64 = -115.99
rel_angle := relativeAngle(lat1, lon1, lat2, lon2)
if rel_angle != 296.565051177078 {
t.Errorf("Angle was incorrect. Expected: 296.565051177078")
}
}
func TestRelativeDirection(t *testing.T) {
var acceptedDirection = []string{"N", "NE", "E", "SE", "S", "SW", "W", "NW"}
for i := 0; i <= 360; i++ {
direction := relativeDirection(float64(i))
if contains(acceptedDirection, direction) == false {
t.Errorf("Direction was incorrect.")
}
}
}
func TestDegrees2Radians(t *testing.T) {
var tests = []struct {
degrees float64
want float64
}{
{234.2376, 4.08821735196947},
{186.3456, 3.2523442666043456},
}
for _, tt := range tests {
testname := fmt.Sprintf("%f", tt.degrees)
t.Run(testname, func(t *testing.T) {
ans := degrees2radians(tt.degrees)
if ans != tt.want {
t.Errorf("got %f, want %f", ans, tt.want)
}
})
}
}
func TestContains(t *testing.T) {
var tests = []struct {
haystack []string
needle string
want bool
}{
{[]string{"N", "NE", "E", "SE", "S", "SW", "W", "NW"}, "SE", true},
{[]string{"foo", "bar"}, "foobar", false},
}
for _, tt := range tests {
testname := fmt.Sprintf("%s,%s", tt.haystack, tt.needle)
t.Run(testname, func(t *testing.T) {
ans := contains(tt.haystack, tt.needle)
if ans != tt.want {
t.Errorf("got %t, want %t", ans, tt.want)
}
})
}
}