-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
86 lines (68 loc) · 1.76 KB
/
utils_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
package main
import (
"testing"
)
// Run with `go test utils_test.go utils.go -bench=.`
var filename = "json/test.json"
var stopfile = "json/transit_stops.json"
var keywordFile = "json/keywords.json"
func BenchmarkReadFileToBytes(b *testing.B) {
for i := 0; i < b.N; i++ {
ReadFileToBytes(filename)
}
}
func TestGetMessageFromRequest(t *testing.T) {
expectedMessage := "Verspätungen der Linie 3 und 10 ab Hauptbahnhof"
jsonBytes := ReadFileToBytes(filename)
resultMessage, _ := GetMessageFromRequest(jsonBytes)
if resultMessage != expectedMessage {
t.Error("String was not cleaned")
}
}
func BenchmarkGetMessageFromRequest(b *testing.B) {
jsonBytes := ReadFileToBytes(filename)
for i := 0; i < b.N; i++ {
GetMessageFromRequest(jsonBytes)
}
}
func TestGetAllTransitStops(t *testing.T) {
namesArray, resultMap := GetAllTransitStops(stopfile)
if len(namesArray) <= 0 {
t.Error("Transit stop map is equals or smaller as 1")
}
if len(resultMap) <= 0 {
t.Error("Transit stop map is equals or smaller as 1")
}
expectedId := "de:14612:834"
resultId := resultMap["steglichstraße"]
if resultId != expectedId {
t.Error("Stop id does not fit")
}
}
func BenchmarkGetAllTransitStops(b *testing.B) {
for i := 0; i < b.N; i++ {
GetAllTransitStops(stopfile)
}
}
func TestGetAllLines(t *testing.T) {
lines := GetAllLines(keywordFile)
if len(lines) <= 0 {
t.Error("Error GetAllLines")
}
}
func BenchmarkGetAllLines(b *testing.B) {
for i := 0; i < b.N; i++ {
GetAllLines(keywordFile)
}
}
func TestGetAllDelayKeywords(t *testing.T) {
delayWords := GetAllDelayKeywords(keywordFile)
if len(delayWords) <= 0 {
t.Error("Error GetAllLines")
}
}
func BenchmarkGetAllDelayKeywords(b *testing.B) {
for i := 0; i < b.N; i++ {
GetAllDelayKeywords(keywordFile)
}
}