-
Notifications
You must be signed in to change notification settings - Fork 3
/
gursShp2geoJson_test.go
182 lines (159 loc) · 4.38 KB
/
gursShp2geoJson_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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package main
import (
"encoding/hex"
"testing"
)
/*
var a []int
func init() {
for i := 0; i < 1000000; i++ {
a = append(a, i)
}
}
func BenchmarkMergeSortMulti(b *testing.B) {
for n := 0; n < b.N; n++ {
MergeSortMulti(a)
}
}
func BenchmarkMergeSort(b *testing.B) {
for n := 0; n < b.N; n++ {
MergeSort(a)
}
}
*/
var encodingTestCases = [...]struct {
win1250, utf string
}{
// https://en.wikipedia.org/wiki/Windows-1250
{"", ""},
{" ", " "},
{"a", "a"},
{"a\nb c123!#", "a\nb c123!#"},
{"\xe8", "č"},
{"abc \xe8\x9e\x9a\xe6\xf0---\xc8\x8e\x8a\xc6\xd0", "abc čžšćđ---ČŽŠĆĐ"},
}
/*
func TestMain(m *testing.M) {
Init()
retCode := m.Run()
//myTeardownFunction()
os.Exit(retCode)
}
*/
func TestDecodeWindows1250(t *testing.T) {
for _, table := range encodingTestCases {
result := DecodeWindows1250(table.win1250)
if result != table.utf {
t.Errorf("Decoding %s: %s gave: %s: %s instead of expected %s: %s", table.win1250, hex.Dump([]byte(table.win1250)), result, hex.Dump([]byte(result)), table.utf, hex.Dump([]byte(table.utf)))
}
}
}
func TestEncodeWindows1250(t *testing.T) {
for _, table := range encodingTestCases {
result := EncodeWindows1250(table.utf)
if result != table.win1250 {
t.Errorf("Encoding %s (%v) gave: %s (%v), instead of expected: %s (%v).", table.utf, hex.Dump([]byte(table.utf)), result, hex.Dump([]byte(result)), table.win1250, hex.Dump([]byte(table.win1250)))
}
}
}
func TestApplyTagLanguagePostfix(t *testing.T) {
assertEqual(t, ApplyTagLanguagePostfix("", 0), ":it")
assertEqual(t, ApplyTagLanguagePostfix("a", 20), "a:hu")
assertEqual(t, ApplyTagLanguagePostfix("ŠomethingUTF", 14.9), "ŠomethingUTF:hu")
assertEqual(t, ApplyTagLanguagePostfix("realistic:tag", 14.2), "realistic:tag:it")
}
func BenchmarkApplyTagLanguagePostfix(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
ApplyTagLanguagePostfix("something", 14.1)
}
}
func TestNormalizeHouseNumbers(t *testing.T) {
//assertEqual(t, NormalizeHouseNumber(""), "000_")
assertEqual(t, NormalizeHouseNumber("a"), "000a")
assertEqual(t, NormalizeHouseNumber("1"), "001_")
assertEqual(t, NormalizeHouseNumber("12"), "012_")
assertEqual(t, NormalizeHouseNumber("2b"), "002b")
assertEqual(t, NormalizeHouseNumber("123c"), "123c")
assertEqual(t, NormalizeHouseNumber("123ž"), "123ž")
}
func BenchmarkNormalizeHouseNumbersWithoutLetter(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
NormalizeHouseNumber("12")
}
}
func BenchmarkNormalizeHouseNumbersWithLetter(b *testing.B) {
b.ReportAllocs()
for n := 0; n < b.N; n++ {
NormalizeHouseNumber("123ž")
}
}
// utility methods
func assertEqual(t *testing.T, testedValue, expected interface{}) {
if testedValue != expected {
t.Errorf("\"%s\" != \"%s\"", testedValue, expected)
}
}
func assertBetween(t *testing.T, testedValue, lowBound, upperBound int) {
if testedValue <= lowBound || testedValue >= upperBound {
t.Errorf("%d should be between %d and %d", testedValue, lowBound, upperBound)
}
}
/*
func TestAll(t *testing.T) {
ReadLookups()
ProcessOne("data/temp/HS-epsg4326/HS-epsg4326.shp")
}
func BenchmarkAll(b *testing.B) {
b.ReportAllocs()
ReadLookups()
for n := 0; n < b.N; n++ {
ProcessOne("data/temp/HS-epsg4326/HS-epsg4326.shp")
}
}
*/
func BenchmarkReadShapefile(b *testing.B) {
if testing.Short() {
b.Skip("skipping test in short mode.")
}
b.ReportAllocs()
ReadLookups()
b.ResetTimer()
_ = ReadShapefile("data/temp/HS-epsg4326/HS-epsg4326.shp")
}
func BenchmarkSort(b *testing.B) {
if testing.Short() {
b.Skip("skipping test in short mode.")
}
b.ReportAllocs()
ReadLookups()
featureCollections := ReadShapefile("data/temp/HS-epsg4326/HS-epsg4326.shp")
b.ResetTimer()
for _, c := range featureCollections {
SortFeatureCollection(*c)
}
}
func BenchmarkReadLookups(b *testing.B) {
if testing.Short() {
b.Skip("skipping test in short mode.")
}
b.ReportAllocs()
ReadLookups()
b.ResetTimer()
ReadLookups()
}
func TestReadLookups(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
ReadLookups()
// just check the length ranges
assertBetween(t, len(ptCodeMap), 400, 500)
assertBetween(t, len(ptNameMap), 400, 500)
assertBetween(t, len(ulNameMap), 10000, 11000)
assertBetween(t, len(ulNameDjMap), 600, 700)
assertBetween(t, len(naNameMap), 6000, 7000)
assertBetween(t, len(naNameDjMap), 50, 60)
assertBetween(t, len(obNameMap), 210, 220)
}