-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatter_test.go
137 lines (119 loc) · 4.04 KB
/
formatter_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
package dms
import "testing"
func TestFormat(t *testing.T) {
var (
def = NewFormatter(SecUnit, 1)
dms = def.WithSymbols("d", "m", "")
dm = NewFormatter(MinUnit, 3)
dd = NewFormatter(DegUnit, 6)
ddn = NewFormatter(DegUnit, -1)
mash = def.WithSep("")
)
tests := []struct {
f *Formatter
angle Angle
result string
}{
{&def, NewAngle(1, 0, 0), "1° 0′ 0.0″"},
{&def, NewAngle(1, 2, 0), "1° 2′ 0.0″"},
{&def, NewAngle(1, 2, 3.33), "1° 2′ 3.3″"},
{&def, NewAngle(-1, 2, 3.33), "-1° 2′ 3.3″"},
{&def, NewAngle(1, -2, -3.33), "1° 2′ 3.3″"},
{&def, NewAngle(-1, 2, 3.36), "-1° 2′ 3.4″"},
{&def, NewAngle(1.051667, 0, 0), "1° 3′ 6.0″"},
{&def, NewAngle(-1.051667, 0, 0), "-1° 3′ 6.0″"},
{&def, NewAngle(1.5, 0, 0), "1° 30′ 0.0″"},
{&def, NewAngle(1.5, 10, 0), "1° 40′ 0.0″"},
{&def, NewAngle(-1.5, 10, 0), "-1° 40′ 0.0″"},
{&def, NewAngle(-1.5, -10, 0), "-1° 40′ 0.0″"},
{&def, NewAngle(1.5, 10.5, 10), "1° 40′ 40.0″"},
{&def, NewAngle(0, 0, 75), "0° 1′ 15.0″"},
{&def, NewAngle(0, 10, 135), "0° 12′ 15.0″"},
{&def, NewAngle(0, 59, 135), "1° 1′ 15.0″"},
{&dms, NewAngle(11, 22, 33.39), "11d 22m 33.4"},
{&dm, NewAngle(1, 0, 0), "1° 0.000′"},
{&dm, NewAngle(1, 2, 0), "1° 2.000′"},
{&dm, NewAngle(1, 2, 6), "1° 2.100′"},
{&dd, NewAngle(1, 0, 0), "1.000000°"},
{&dd, NewAngle(1, 3, 0), "1.050000°"},
{&dd, NewAngle(1, 3, 9), "1.052500°"},
{&ddn, NewAngle(1, 0, 0), "1°"},
{&mash, NewAngle(1, 2, 3.33), "1°2′3.3″"},
}
for _, test := range tests {
t.Run(test.result, func(t *testing.T) {
result := test.f.Format(test.angle)
if result != test.result {
t.Errorf("\n have: [%v] \n want: [%v]\n", result, test.result)
}
})
}
}
func TestFormatLat(t *testing.T) {
var (
def = NewFormatter(SecUnit, 1)
dms = def.WithSymbols("d", "m", "")
dm = NewFormatter(MinUnit, 3)
dd = NewFormatter(DegUnit, 6)
ddn = NewFormatter(DegUnit, -1)
mash = def.WithSep("")
)
tests := []struct {
f *Formatter
angle Angle
result string
}{
{&def, NewAngle(1, 0, 0), "1° 0′ 0.0″ N"},
{&def, NewAngle(1, 2, 0), "1° 2′ 0.0″ N"},
{&def, NewAngle(1, 2, 3.33), "1° 2′ 3.3″ N"},
{&def, NewAngle(-1, 2, 3.33), "1° 2′ 3.3″ S"},
{&def, NewAngle(1, -2, -3.33), "1° 2′ 3.3″ N"},
{&def, NewAngle(-1, 2, 3.36), "1° 2′ 3.4″ S"},
{&def, NewAngle(1.051667, 0, 0), "1° 3′ 6.0″ N"},
{&def, NewAngle(-1.051667, 0, 0), "1° 3′ 6.0″ S"},
{&def, NewAngle(1.5, 0, 0), "1° 30′ 0.0″ N"},
{&def, NewAngle(1.5, 10, 0), "1° 40′ 0.0″ N"},
{&def, NewAngle(-1.5, 10, 0), "1° 40′ 0.0″ S"},
{&def, NewAngle(-1.5, -10, 0), "1° 40′ 0.0″ S"},
{&def, NewAngle(1.5, 10.5, 10), "1° 40′ 40.0″ N"},
{&def, NewAngle(0, 0, 75), "0° 1′ 15.0″ N"},
{&def, NewAngle(0, 10, 135), "0° 12′ 15.0″ N"},
{&def, NewAngle(0, 59, 135), "1° 1′ 15.0″ N"},
{&dms, NewAngle(11, 22, 33.39), "11d 22m 33.4 N"},
{&dm, NewAngle(1, 0, 0), "1° 0.000′ N"},
{&dm, NewAngle(1, 2, 0), "1° 2.000′ N"},
{&dm, NewAngle(1, 2, 6), "1° 2.100′ N"},
{&dd, NewAngle(1, 0, 0), "1.000000° N"},
{&dd, NewAngle(1, 3, 0), "1.050000° N"},
{&dd, NewAngle(1, 3, 9), "1.052500° N"},
{&ddn, NewAngle(1, 0, 0), "1° N"},
{&mash, NewAngle(1, 2, 3.33), "1°2′3.3″N"},
}
for _, test := range tests {
t.Run(test.result, func(t *testing.T) {
result := test.f.FormatLat(test.angle)
if result != test.result {
t.Errorf("\n have: [%v] \n want: [%v]\n", result, test.result)
}
})
}
}
func TestFormatLon(t *testing.T) {
def := NewFormatter(SecUnit, 1)
tests := []struct {
f *Formatter
angle Angle
result string
}{
{&def, NewAngle(1, 0, 0), "1° 0′ 0.0″ E"},
{&def, NewAngle(-1, 2, 0), "1° 2′ 0.0″ W"},
}
for _, test := range tests {
t.Run(test.result, func(t *testing.T) {
result := test.f.FormatLon(test.angle)
if result != test.result {
t.Errorf("\n have: [%v] \n want: [%v]\n", result, test.result)
}
})
}
}