-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextprocessing_test.go
127 lines (104 loc) · 2.4 KB
/
textprocessing_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
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"testing"
"strings"
)
// Run with `go test textprocessing_test.go textprocessing.go utils.go textinfo.go -bench=.`
var testStr = "Abfahrten. der, Linie? 3! ab Hauptbahnhof;"
var expectedStr = "Abfahrten der Linie 3 ab Hauptbahnhof"
func TestCleanString(t *testing.T) {
result := CleanString(testStr)
if result != expectedStr {
t.Error("String was not cleaned")
}
}
func BenchmarkCleanWord(b *testing.B) {
for i := 0; i < b.N; i++ {
CleanString(testStr)
}
}
func TestFindStops(t *testing.T) {
expectedStr = strings.ToLower(expectedStr)
wordArray := strings.Split(expectedStr, " ")
stopName, stopNr := "", ""
for id, word := range wordArray {
isLast := false
words := []string{}
if id != 0 {
words = append(words, wordArray[id-1])
}
words = append(words, word)
if id != len(wordArray)-1 {
words = append(words, wordArray[id+1])
} else {
isLast = true
}
stopName, stopNr = FindStops(words, isLast)
}
if stopName == "" && stopNr == "" {
t.Error("Can't find stop")
}
}
func BenchmarkFindStops(b *testing.B) {
for i := 0; i < b.N; i++ {
expectedStr = strings.ToLower(expectedStr)
wordArray := strings.Split(expectedStr, " ")
for id, word := range wordArray {
isLast := false
words := []string{}
if id != 0 {
words = append(words, wordArray[id-1])
}
words = append(words, word)
if id != len(wordArray)-1 {
words = append(words, wordArray[id+1])
} else {
isLast = true
}
FindStops(words, isLast)
}
}
}
func TestSearch(t *testing.T) {
wordGroup := "hauptbahnho"
stopName, stopNr := search(wordGroup)
if stopName != "hauptbahnhof" || stopNr != "de:14612:28" {
t.Error("Can't find stop")
}
}
func BenchmarkSearch(b *testing.B) {
wordGroup := "hauptbahnho"
for i := 0; i < b.N; i++ {
search(wordGroup)
}
}
func TestIsLine(t *testing.T) {
word1 := "3"
word2 := "kebab"
if !isLine(word1) {
t.Error("TestIsLine: Should be true.")
}
if isLine(word2) {
t.Error("TestIsLine: Should be false.")
}
}
func BenchmarkIsLine(b *testing.B) {
for i := 0; i < b.N; i++ {
isLine("61")
}
}
func TestIsDelayWord(t *testing.T) {
word1 := "verspätungen"
word2 := "kebab"
if !isDelayWord(word1) {
t.Error("TestIsDelayWord: Should be true.")
}
if isDelayWord(word2) {
t.Error("TestIsDelayWord: Should be false.")
}
}
func BenchmarkIsDelayWord(b *testing.B) {
for i := 0; i < b.N; i++ {
isLine("verspätungen")
}
}