-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtzf_default_finder_test.go
71 lines (62 loc) · 1.49 KB
/
tzf_default_finder_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
package tzf_test
import (
"bytes"
"fmt"
"runtime"
"testing"
"github.com/loov/hrtime/hrtesting"
gocitiesjson "github.com/ringsaturn/go-cities.json"
"github.com/ringsaturn/tzf"
"github.com/tidwall/lotsa"
)
var (
defaultFinder tzf.F
)
func init() {
finder, err := tzf.NewDefaultFinder()
if err != nil {
panic(err)
}
defaultFinder = finder
}
func ExampleDefaultFinder_GetTimezoneName() {
finder, err := tzf.NewDefaultFinder()
if err != nil {
panic(err)
}
fmt.Println(finder.GetTimezoneName(116.6386, 40.0786))
// Output: Asia/Shanghai
}
func ExampleDefaultFinder_GetTimezoneNames() {
finder, err := tzf.NewDefaultFinder()
if err != nil {
panic(err)
}
fmt.Println(finder.GetTimezoneNames(87.6168, 43.8254))
// Output: [Asia/Shanghai Asia/Urumqi] <nil>
}
func ExampleDefaultFinder_TimezoneNames() {
finder, err := tzf.NewDefaultFinder()
if err != nil {
panic(err)
}
fmt.Println(finder.TimezoneNames())
}
func BenchmarkDefaultFinder_GetTimezoneName_Random_WorldCities(b *testing.B) {
bench := hrtesting.NewBenchmark(b)
defer bench.Report()
for bench.Next() {
p := gocitiesjson.Random()
_ = defaultFinder.GetTimezoneName(p.Lng, p.Lat)
}
}
func Test_DefaultFinder_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]
_ = defaultFinder.GetTimezoneName(city.Lng, city.Lat)
})
testing.Verbose()
t.Log(wri.String())
}