-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtcnextbus_test.go
75 lines (70 loc) · 1.97 KB
/
mtcnextbus_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
package main
import (
"fmt"
"strings"
"testing"
)
func TestGetRouteID(t *testing.T) {
cases := []struct {
in, want string
}{
{"Express - Target - Hwy 252 and 73rd Av P&R - Mpls", "765"},
{"METRO Blue Line", "901"},
}
for _, c := range cases {
got, err := getRouteID(c.in)
if got != c.want {
t.Errorf("getRouteID(%q) == %q, want %q, error: %v", c.in, got, c.want, err)
}
}
}
func TestGetDirectionID(t *testing.T) {
cases := []struct {
in, in2, want string
}{
{"765", "south", "1"},
{"901", "north", "4"},
}
for _, c := range cases {
got, err := getDirectionID(c.in, c.in2)
if got != c.want {
t.Errorf("getDirectionID(%q, %q) == %q, want %q, error: %v", c.in, c.in2, got, c.want, err)
}
}
}
func TestGetStopID(t *testing.T) {
cases := []struct {
in, in2, in3, want string
}{
{"765", "1", "Target North Campus Building F", "TGBF"},
{"901", "4", "Target Field Station Platform 1", "TF1I"},
}
for _, c := range cases {
got, err := getStopID(c.in, c.in2, c.in3)
if got != c.want {
t.Errorf("getStopID(%q, %q, %q) == %q, want %q, error: %v", c.in, c.in2, c.in3, got, c.want, err)
}
}
}
func TestGetDeparture(t *testing.T) {
cases := []struct {
in, in2, in3, want, okerr string
}{
{"765", "1", "TGBF", "Min", "No upcoming departures found for today."},
{"901", "4", "TF1I", "Min", "No upcoming departures found for today."},
{"", "", "", "", "error getting departures: bad response code from API: 404 Not Found"},
}
for _, c := range cases {
got, err := getDeparture(c.in, c.in2, c.in3)
if strings.Contains(got, c.want) == false && strings.Contains(got, "Due") == false {
if fmt.Sprintf("%s", err) != c.okerr {
t.Errorf("getDeparture(%q, %q, %q) == %q, want %q or err %q, error: %v", c.in, c.in2, c.in3, got, c.want, c.okerr, err)
}
}
if err != nil {
if fmt.Sprintf("%s", err) != c.okerr {
t.Errorf("getDeparture(%q, %q, %q) == %q, want %q or err %q, error: %v", c.in, c.in2, c.in3, got, c.want, c.okerr, err)
}
}
}
}