-
Notifications
You must be signed in to change notification settings - Fork 5
/
gocoord_test.go
167 lines (131 loc) · 3.75 KB
/
gocoord_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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package gocoord
import (
"math"
"testing"
//"github.com/suifengtec/gocoord"
)
var testsCases = []struct {
from Position
expectedValue Position
}{
{ // BD09ToGCJ02
Position{Lon: 113.739873, Lat: 34.356696},
Position{Lon: 113.73337197243862, Lat: 34.350630274732744},
},
{ //BD09ToWGS84
Position{Lon: 113.739873, Lat: 34.356696},
Position{Lon: 113.7272281721665, Lat: 34.351951705458674},
},
{ //WGS84ToBD09
Position{Lon: 113.739873, Lat: 34.356696},
Position{Lon: 113.75246057307969, Lat: 34.3616443275599},
},
{ //WGS84ToGCJ02
Position{Lon: 113.739873, Lat: 34.356696},
Position{Lon: 113.74601884470827, Lat: 34.35538495876689},
},
{ //GCJ02ToBD09
Position{Lon: 113.739873, Lat: 34.356696},
Position{Lon: 113.7463400404353, Lat: 34.36287007240432},
},
{ //GCJ02ToWGS84
Position{Lon: 113.739873, Lat: 34.356696},
Position{Lon: 113.73372688226371, Lat: 34.358009517422026},
},
{ //BD09toBD09MC
Position{Lon: 113.739873, Lat: 34.356696},
Position{Lon: 1.266160251233583e+07, Lat: 4.052461800944403e+06},
},
{ //BD09MCtoBD09
Position{Lon: 113.739873, Lat: 34.356696},
Position{Lon: 0.0010217344366200546, Lat: 0.000310700669093249},
},
}
func TestBD09ToGCJ02(t *testing.T) {
input := testsCases[0]
ret := BD09ToGCJ02(input.from)
if math.Abs(ret.Lat-input.expectedValue.Lat) > 1e-6 {
t.Errorf("FAIL: BD09ToGCJ02 测试的输入是 %#v ,期望得到 : %#v ,但计算结果为 %#v",
input.from,
input.expectedValue,
ret,
)
}
}
func TestBD09ToWGS84(t *testing.T) {
input := testsCases[1]
ret := BD09ToWGS84(input.from)
if math.Abs(ret.Lat-input.expectedValue.Lat) > 1e-6 {
t.Errorf("FAIL: BD09ToWGS84 测试的输入是 %#v ,期望得到 : %#v ,但计算结果为 %#v",
input.from,
input.expectedValue,
ret,
)
}
}
func TestWGS84ToBD09(t *testing.T) {
input := testsCases[2]
ret := WGS84ToBD09(input.from)
if math.Abs(ret.Lat-input.expectedValue.Lat) > 1e-3 {
t.Errorf("FAIL: WGS84ToBD09 测试的输入是 %#v ,期望得到 : %#v ,但计算结果为 %#v",
input.from,
input.expectedValue,
ret,
)
}
}
func TestWGS84ToGCJ02(t *testing.T) {
input := testsCases[3]
ret := WGS84ToGCJ02(input.from)
if math.Abs(ret.Lat-input.expectedValue.Lat) > 1e-3 {
t.Errorf("FAIL: WGS84ToGCJ02 测试的输入是 %#v ,期望得到 : %#v ,但计算结果为 %#v",
input.from,
input.expectedValue,
ret,
)
}
}
func TestGCJ02ToBD09(t *testing.T) {
input := testsCases[4]
ret := GCJ02ToBD09(input.from)
if math.Abs(ret.Lat-input.expectedValue.Lat) > 1e-3 {
t.Errorf("FAIL: GCJ02ToBD09 测试的输入是 %#v ,期望得到 : %#v ,但计算结果为 %#v",
input.from,
input.expectedValue,
ret,
)
}
}
func TestGCJ02ToWGS84(t *testing.T) {
input := testsCases[5]
ret := GCJ02ToWGS84(input.from)
if math.Abs(ret.Lat-input.expectedValue.Lat) > 1e-3 {
t.Errorf("FAIL: GCJ02ToWGS84 测试的输入是 %#v ,期望得到 : %#v ,但计算结果为 %#v",
input.from,
input.expectedValue,
ret,
)
}
}
func TestBD09toBD09MC(t *testing.T) {
input := testsCases[6]
ret := BD09toBD09MC(input.from)
if math.Abs(ret.Lat-input.expectedValue.Lat) > 1e-3 {
t.Errorf("FAIL: BD09toBD09MC 测试的输入是 %#v ,期望得到 : %#v ,但计算结果为 %#v",
input.from,
input.expectedValue,
ret,
)
}
}
func TestBD09MCtoBD09(t *testing.T) {
input := testsCases[7]
ret := BD09MCtoBD09(input.from)
if math.Abs(ret.Lat-input.expectedValue.Lat) > 1e-3 {
t.Errorf("FAIL: BD09MCtoBD09 测试的输入是 %#v ,期望得到 : %#v ,但计算结果为 %#v",
input.from,
input.expectedValue,
ret,
)
}
}