-
Notifications
You must be signed in to change notification settings - Fork 3
/
grammar_test.go
146 lines (120 loc) · 3.09 KB
/
grammar_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package grammar
import "testing"
func TestLoadRegular(t *testing.T) {
t.Parallel()
// Try to properly load a regular sentence.
negative(t, "This sentence is fine.")
}
func TestLoadBlank(t *testing.T) {
t.Parallel()
// Try to load an empty string.
negative(t, "")
}
func TestUnicode(t *testing.T) {
t.Parallel()
positive(t, "… → their is …", "→ [there] is")
}
func TestWordCase(t *testing.T) {
t.Parallel()
// lowercase detection
positive(t, "their is", "[there] is")
// Titlecase Detection
positive(t, "Their is", "[There] is")
// UPPERCASE DETECTION
positive(t, "THEIR is", "[THERE] is")
}
func TestOverlap(t *testing.T) {
t.Parallel()
positive(t, "Their is you're own", "[There] is [your] own")
positive(t, "Your you're own", "[You're your] own")
positive(t, "Its there own item", "[It's their] own item")
positive(t, "Its it's own item", "[It's its] own item")
positive(t, "Your don't supposed to!", "[You aren't] supposed to!")
}
func TestPunctuation(t *testing.T) {
t.Parallel()
// Keep question marks and exclamation marks
positive(t, "their is?", "[there] is?")
positive(t, "their is!", "[there] is!")
// Original punctuation should be out of the brackets
positive(t, "I am hear!", "I am [here]!")
// Drop leading and trailing spaces
positive(t, " their is ", "[there] is")
// Retain double spaces
positive(t, "their is", "[there] is")
// Drop periods, commas, and semicolons
positive(t, "their is.", "[there] is")
positive(t, "their is,", "[there] is")
positive(t, "their is;", "[there] is")
}
func TestWording(t *testing.T) {
// t.Parallel()
// Verify that wording can be generated without failing
r := MakeTweetReply("Their is and your don't supposed to! (blah) They think their is.", "@@")
if r != "" {
t.Logf("Reply: %q", r)
} else {
t.Errorf("Expected non-empty reply")
}
}
func TestWordingEmpty(t *testing.T) {
// t.Parallel()
// Verify that wording can be generated without failing
r := MakeTweetReply("This sentence is acceptable.", "@@")
if r != "" {
t.Errorf("Expected empty reply")
}
}
var corrections, why []string
func BenchmarkShortOK(b *testing.B) {
var c, w []string
for n := 0; n < b.N; n++ {
c, w = Load("Nothing's wrong with this sentence.")
}
corrections = c
why = w
}
func BenchmarkShortDetect(b *testing.B) {
var c, w []string
for n := 0; n < b.N; n++ {
c, w = Load("But it's true that their is a problem with this sentence.")
}
corrections = c
why = w
}
func BenchmarkLongOK(b *testing.B) {
s := "Nothing's wrong with this sentence. "
for i := 0; i < 10; i++ {
s += s
}
var c, w []string
for n := 0; n < b.N; n++ {
c, w = Load(s)
}
corrections = c
why = w
}
func BenchmarkLongDetect(b *testing.B) {
s := "But it's true that their is a problem with this sentence. "
for i := 0; i < 10; i++ {
s += s
}
var c, w []string
for n := 0; n < b.N; n++ {
c, w = Load(s)
}
corrections = c
why = w
}
func BenchmarkVeryLongOK(b *testing.B) {
s := "Nothing's wrong with this sentence. "
for i := 0; i < 15; i++ {
s += s
}
var c, w []string
for n := 0; n < b.N; n++ {
c, w = Load(s)
}
corrections = c
why = w
}