-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgps_time_test.go
146 lines (137 loc) · 5 KB
/
gps_time_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package timex
import (
"reflect"
"testing"
"time"
)
func TestGps(t *testing.T) {
type args struct {
offset time.Duration
}
tests := []struct {
name string
args args
want GpsTime
}{
{"Epoch", args{0}, GpsTime(gpsDatum)},
{"Inside leap table", args{948731799 * time.Second}, GpsTime(time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC))},
{"Before leap table", args{-315187200 * time.Second}, GpsTime(time.Date(1970, time.January, 10, 0, 0, 0, 0, time.UTC))},
{"After leap table", args{1436486418 * time.Second}, GpsTime(time.Date(2025, time.July, 14, 0, 0, 0, 0, time.UTC))},
{"Before leap", args{1025136014 * time.Second}, GpsTime(time.Date(2012, time.June, 30, 23, 59, 59, 0, time.UTC))},
{"After leap", args{1025136016 * time.Second}, GpsTime(time.Date(2012, time.July, 1, 0, 0, 0, 0, time.UTC))},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Gps(tt.args.offset); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Gps() = %v, want %v", got, tt.want)
}
})
}
}
func TestGpsTime_Gps(t *testing.T) {
tests := []struct {
name string
t GpsTime
want time.Duration
}{
{"GPS Datum", GpsTime(gpsDatum), 0},
{"Inside leap table", GpsTime(time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC)), 948731799 * time.Second},
{"Before leap table", GpsTime(time.Date(1970, time.January, 10, 0, 0, 0, 0, time.UTC)), -315187200 * time.Second},
{"After leap table", GpsTime(time.Date(2025, time.July, 14, 0, 0, 0, 0, time.UTC)), 1436486418 * time.Second},
{"Before leap", GpsTime(time.Date(2012, time.June, 30, 23, 59, 59, 0, time.UTC)), 1025136014 * time.Second},
{"After leap", GpsTime(time.Date(2012, time.July, 1, 0, 0, 0, 0, time.UTC)), 1025136016 * time.Second},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.t.Gps(); got != tt.want {
t.Errorf("GpsTime.Gps() = %v, want %v", got, tt.want)
}
})
}
}
func TestString(t *testing.T) {
value := time.Now()
gps := GpsTime(value)
got := gps.String()
want := value.String()
if got != want {
t.Errorf("String() = %v, want %v", got, want)
}
}
func TestGpsTime_ToUTC(t *testing.T) {
tests := []struct {
name string
t GpsTime
want time.Time
}{
{"GPS Datum", GpsTime(gpsDatum), gpsDatum},
{"Inside leap table", GpsTime(time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC)), time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC)},
{"Before leap table", GpsTime(time.Date(1970, time.January, 10, 0, 0, 0, 0, time.UTC)), time.Date(1970, time.January, 10, 0, 0, 0, 0, time.UTC)},
{"After leap table", GpsTime(time.Date(2025, time.July, 14, 0, 0, 0, 0, time.UTC)), time.Date(2025, time.July, 14, 0, 0, 0, 0, time.UTC)},
{"Before leap", GpsTime(time.Date(2012, time.June, 30, 23, 59, 59, 0, time.UTC)), time.Date(2012, time.June, 30, 23, 59, 59, 0, time.UTC)},
{"After leap", GpsTime(time.Date(2012, time.July, 1, 0, 0, 0, 0, time.UTC)), time.Date(2012, time.July, 1, 0, 0, 0, 0, time.UTC)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.t.ToUTC(); got != tt.want {
t.Errorf("GpsTime.ToUTC() = %v, want %v", got, tt.want)
}
})
}
}
func TestGpsTime_Add(t *testing.T) {
tests := []struct {
name string
t GpsTime
d time.Duration
want GpsTime
}{
{"GPS Datum", GpsTime(gpsDatum), 5 * time.Second, GpsTime(gpsDatum.Add(5 * time.Second))},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.t.Add(tt.d); got != tt.want {
t.Errorf("GpsTime.Add() = %v, want %v", got, tt.want)
}
})
}
}
func TestGpsTime_Sub(t *testing.T) {
tests := []struct {
name string
t GpsTime
u GpsTime
want time.Duration
}{
{"GPS Datum", GpsTime(gpsDatum), GpsTime(gpsDatum), 0},
{"Inside leap table", GpsTime(time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC)), GpsTime(time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC)), 0},
{"Inside leap table vs GPS Datum", GpsTime(time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC)), GpsTime(gpsDatum), 948731799 * time.Second},
{"GPS Datum vs Inside leap table", GpsTime(gpsDatum), GpsTime(time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC)), -948731799 * time.Second},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.t.Sub(tt.u); got != tt.want {
t.Errorf("GpsTime.Sub() = %v, want %v", got, tt.want)
}
})
}
}
func TestGpsTime_Equal(t *testing.T) {
tests := []struct {
name string
t GpsTime
u GpsTime
want bool
}{
{"GPS Datum", GpsTime(gpsDatum), GpsTime(gpsDatum), true},
{"Inside leap table", GpsTime(time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC)), GpsTime(time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC)), true},
{"GPS Datum vs Inside leap table", GpsTime(gpsDatum), GpsTime(time.Date(2010, time.January, 28, 16, 36, 24, 0, time.UTC)), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.t.Equal(tt.u); got != tt.want {
t.Errorf("GpsTime.Equal() = %v, want %v", got, tt.want)
}
})
}
}