-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpx_test.go
101 lines (91 loc) · 2.17 KB
/
gpx_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"math"
"os"
"testing"
"time"
)
func TestGPXNoSuchFile(t *testing.T) {
time := time.Time{}
_, _, _, err := getMetadataFromGPX(time, "junk")
if err == nil {
t.Errorf("didn't fail")
}
}
func TestGPXJunkFile(t *testing.T) {
time := time.Time{}
_, _, _, err := getMetadataFromGPX(time, "testdata/junk.gpx")
if err == nil {
t.Errorf("didn't fail")
}
}
func TestGPXNotFoundGood1(t *testing.T) {
time := time.Time{}
lat, lon, ele, err := getMetadataFromGPX(time, "testdata/good1.gpx")
if err != nil {
t.Errorf("unexpected fail %v", err)
}
if lat != 0.0 {
t.Errorf("lat valid %v", lat)
}
if lon != 0.0 {
t.Errorf("lon valid %v", lon)
}
if ele != 0.0 {
t.Errorf("ele valid %v", ele)
}
}
func TestGPXFoundGood1(t *testing.T) {
time := time.Date(2022, time.October, 22, 8, 10, 0, 0, time.UTC)
lat, lon, ele, err := getMetadataFromGPX(time, "testdata/good1.gpx")
if err != nil {
t.Errorf("unexpected fail %v", err)
}
if math.Abs(lat-51.0) > 1e-9 {
t.Errorf("lat valid %v", lat)
}
if math.Abs(lon - -3) > 1e-9 {
t.Errorf("lon valid %v", lon)
}
if math.Abs(ele-139.05) > 1e-9 {
t.Errorf("ele valid %v", ele)
}
}
func TestGPXOverrunGood1(t *testing.T) {
time := time.Date(2023, time.October, 22, 8, 40, 0, 0, time.UTC)
_, _, _, err := getMetadataFromGPX(time, "testdata/good1.gpx")
if err == nil {
t.Errorf("didn't fail")
}
}
func TestGPXJunkOutputMerge1(t *testing.T) {
err := mergeGPX([]string{"testdata/good1.gpx"}, "")
if err == nil {
t.Errorf("didn't fail")
}
}
func TestGPXJunkInputtMerge1(t *testing.T) {
err := mergeGPX([]string{"junk.gpx"}, "")
if err == nil {
t.Errorf("didn't fail")
}
}
func TestGPXJunkInputtMerge2(t *testing.T) {
err := mergeGPX([]string{"testdata/junk.gpx"}, "")
if err == nil {
t.Errorf("didn't fail")
}
}
func TestGPXGoodMerge1(t *testing.T) {
f, _ := os.CreateTemp("", "out.gpx")
defer os.Remove(f.Name())
err := mergeGPX([]string{"testdata/good1.gpx"}, f.Name())
if err != nil {
t.Errorf("failed %v", err)
}
time := time.Date(2022, time.October, 22, 8, 10, 0, 0, time.UTC)
_, _, _, err = getMetadataFromGPX(time, f.Name())
if err != nil {
t.Errorf("couldnt read mergerd file %v", err)
}
}