-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtzf_test.go
93 lines (83 loc) · 2.23 KB
/
tzf_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
package tzf_test
import (
"bytes"
"fmt"
"runtime"
"testing"
"github.com/loov/hrtime/hrtesting"
gocitiesjson "github.com/ringsaturn/go-cities.json"
"github.com/ringsaturn/tzf"
tzfrellite "github.com/ringsaturn/tzf-rel-lite"
"github.com/ringsaturn/tzf/pb"
"github.com/tidwall/lotsa"
"google.golang.org/protobuf/proto"
)
var finder tzf.F = func() tzf.F {
input := &pb.Timezones{}
if err := proto.Unmarshal(tzfrellite.LiteData, input); err != nil {
panic(err)
}
finder, err := tzf.NewFinderFromPB(input)
if err != nil {
panic(err)
}
return finder
}()
func BenchmarkGetTimezoneName(b *testing.B) {
bench := hrtesting.NewBenchmark(b)
defer bench.Report()
for bench.Next() {
_ = finder.GetTimezoneName(116.6386, 40.0786)
}
}
func BenchmarkGetTimezoneNameAtEdge(b *testing.B) {
bench := hrtesting.NewBenchmark(b)
defer bench.Report()
for bench.Next() {
_ = finder.GetTimezoneName(110.8571, 43.1483)
}
}
func BenchmarkGetTimezoneName_Random_WorldCities(b *testing.B) {
bench := hrtesting.NewBenchmark(b)
defer bench.Report()
for bench.Next() {
p := gocitiesjson.Random()
_ = finder.GetTimezoneName(p.Lng, p.Lat)
}
}
func ExampleFinder_GetTimezoneName() {
input := &pb.Timezones{}
if err := proto.Unmarshal(tzfrellite.LiteData, input); err != nil {
panic(err)
}
finder, _ := tzf.NewFinderFromPB(input)
fmt.Println(finder.GetTimezoneName(116.6386, 40.0786))
// Output: Asia/Shanghai
}
func ExampleFinder_GetTimezoneNames() {
input := &pb.Timezones{}
if err := proto.Unmarshal(tzfrellite.LiteData, input); err != nil {
panic(err)
}
finder, _ := tzf.NewFinderFromPB(input)
fmt.Println(finder.GetTimezoneNames(87.6168, 43.8254))
// Output: [Asia/Shanghai Asia/Urumqi] <nil>
}
func ExampleFinder_TimezoneNames() {
input := &pb.Timezones{}
if err := proto.Unmarshal(tzfrellite.LiteData, input); err != nil {
panic(err)
}
finder, _ := tzf.NewFinderFromPB(input)
fmt.Println(finder.TimezoneNames())
}
func Test_Finder_GetTimezoneName_Random_WorldCities_Alll(t *testing.T) {
wri := bytes.NewBufferString("")
lotsa.Output = wri
lotsa.Ops(len(gocitiesjson.Cities), runtime.NumCPU(), func(i, _ int) {
city := gocitiesjson.Cities[i]
_ = finder.GetTimezoneName(city.Lng, city.Lat)
})
testing.Verbose()
t.Log(wri.String())
}