-
Notifications
You must be signed in to change notification settings - Fork 3
/
fake_test.go
116 lines (97 loc) · 2.54 KB
/
fake_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
package main
import (
"encoding/xml"
"testing"
)
func TestInit(t *testing.T) {
var testFakeBus FakeBus
if len(testFakeBus.BusInstances) != 0 {
t.Fatalf("expected empty fakeBus.BusInstances, got %v", len(testFakeBus.BusInstances))
}
testFakeBus.Init()
if len(testFakeBus.BusInstances) != 2 {
t.Fatalf("expected len(fakeBus.BusInstances) is 2, got %v", len(testFakeBus.BusInstances))
}
}
func TestGetBusRoute(t *testing.T) {
var testFakeBus FakeBus
Expected := BusRoute{xml.Name{}, 2, "수원",
"201320974", "2018-1", "테스트용시내버스", 0}
testFakeBus.Init()
ret := testFakeBus.GetBusRoute()
if ret != Expected {
t.Fatalf("expected BusRoute: %v, got %v", Expected, ret)
}
}
func TestGetBusRouteInfo(t *testing.T) {
var testFakeBus FakeBus
Expected := BusRouteInfoItem{xml.Name{}, 2, "00:00", "00:00",
"03129", "202000004", "아주대학교입구", "수원", "201320974",
"2018-1", "테스트용시내버스", "04238", "203000067",
"아주대학교입구", "00:00", "00:00"}
testFakeBus.Init()
ret := testFakeBus.GetBusRouteInfo()
if ret != Expected {
t.Fatalf("expected BusRouteInfo: %v, got %v", Expected, ret)
}
}
func TestGetBusRouteStationList(t *testing.T) {
var testFakeBus FakeBus
testFakeBus.Init()
if ret := testFakeBus.GetBusRouteStationList(); len(ret) != 8 {
t.Fatalf("expected length is %v, got %v", 8, len(ret))
}
}
func TestFakeBusGetCurrentBusLocation(t *testing.T) {
var testFakeBus FakeBus
testFakeBus.Init()
if ret := testFakeBus.GetCurrentBusLocation(); len(ret) != 2 {
t.Fatalf("expected length is %v, got %v", 2, len(ret))
}
}
func TestIsInBusList(t *testing.T) {
var testFakeBus FakeBus
testFakeBus.Init()
tt := []struct {
value string
result bool
}{
{"202000004", true},
{"200000000", false},
}
for _, tc := range tt {
if ret := testFakeBus.IsInBusList(tc.value); ret != tc.result {
t.Fatalf("expected value: %v, got %v", tc.result, ret)
}
}
}
func TestGetBusArrival(t *testing.T) {
var testFakeBus FakeBus
Expected := BusArrival{
xml.Name{},
3, 7, -1, -1,
"경기96희0820", "경기93범1004",
3, 7, 23, 17,
"201320974", "2018-1", "테스트용시내버스", 8,
}
testFakeBus.Init()
ret := testFakeBus.GetBusArrival("202000038")
if ret != Expected {
t.Fatalf("expected BusArrival: %v, got %v", Expected, ret)
}
}
func TestAbs(t *testing.T) {
tt := []struct {
value int
result int
}{
{1, 1},
{-1, 1},
{0, 0},
}
for _, tc := range tt {
if ret := abs(tc.value); ret != tc.result {
t.Fatalf("expected value: %v, got %v", tc.result, ret)
}
}
}