-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbusstops_test.go
89 lines (83 loc) · 1.84 KB
/
busstops_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
package main
import (
"reflect"
"testing"
)
// We need to ensure compiler actually returns the value
// A clever compiler might optimise it out, rendering our
// benchmarking results incorrect
var stop BusStop
func Benchmark_closest(b *testing.B) {
bs, _ := loadBusJSON("static/all.json")
b.ResetTimer()
for n := 0; n < b.N; n++ {
stop = bs.closest(Point{}) // ensure the compiler returns a value
}
}
func TestBusStops_closest(t *testing.T) {
bs, _ := loadBusJSON("static/all.json")
type args struct {
location Point
}
tests := []struct {
name string
BusStops BusStops
args args
wantB BusStop
}{
{
name: "Middle Earth",
BusStops: bs,
args: args{
location: Point{
lat: 0.0,
lng: 0.0,
},
},
wantB: BusStop{
BusStopCode: "25059",
RoadName: "Tuas Sth Way",
Description: "Aft Tuas Sth Blvd",
Latitude: 1.270007,
Longitude: 103.61725,
},
},
}
for _, tt := range tests {
t.Parallel()
t.Run(tt.name, func(t *testing.T) {
if gotB := tt.BusStops.closest(tt.args.location); !reflect.DeepEqual(gotB, tt.wantB) {
t.Errorf("BusStops.closest() = %+v, want %+v", gotB, tt.wantB)
}
})
}
}
func TestBusStops_nameBusStopID(t *testing.T) {
bs, _ := loadBusJSON("static/all.json")
type args struct {
busid string
}
tests := []struct {
name string
BusStops BusStops
args args
wantDescription string
}{
{
name: "Bras Basah",
BusStops: bs,
args: args{
busid: "01019",
},
wantDescription: "Bras Basah Cplx",
},
}
for _, tt := range tests {
t.Parallel()
t.Run(tt.name, func(t *testing.T) {
if gotDescription := tt.BusStops.nameBusStop(tt.args.busid); gotDescription != tt.wantDescription {
t.Errorf("BusStops.nameBusStopID() = %v, want %v", gotDescription, tt.wantDescription)
}
})
}
}