-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_token.h
87 lines (67 loc) · 2.24 KB
/
clean_token.h
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
#include <gtest/gtest.h>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include "search.h"
using namespace std;
void testCleanToken(const map<string, set<string>>& tests) {
for (const auto& [expected, tokens] : tests) {
for (const auto& toClean : tokens) {
string studentResult = cleanToken(toClean);
string testFeedback = "cleanToken(\"" + toClean + "\") incorrect\n";
EXPECT_EQ(expected, studentResult) << testFeedback;
}
}
}
// Tokens without any punctuation or special characters
TEST(CleanToken, NoCleaning) {
map<string, set<string>> tests;
tests["same"].insert("same");
tests["wander"].insert("wander");
tests["l33tcode"].insert("l33tcode");
testCleanToken(tests);
}
// Tokens with punctuation at the beginning
TEST(CleanToken, PrefixCleaning) {
map<string, set<string>> tests;
tests["hello"].insert(".hello");
tests["hello"].insert("...hello");
tests["hello"].insert(".\"!?hello");
tests["timesheet"].insert(";timesheet");
tests["timesheet"].insert(";.!timesheet");
tests["timesheet"].insert(".,.!?timesheet");
testCleanToken(tests);
}
// Tokens with punctuation at the end
TEST(CleanToken, SuffixCleaning) {
map<string, set<string>> tests;
tests["hello"].insert("hello.");
tests["hello"].insert("hello...");
tests["hello"].insert("hello.\"!?");
tests["timesheet"].insert("timesheet;");
tests["timesheet"].insert("timesheet;.!");
tests["timesheet"].insert("timesheet.,.!?");
testCleanToken(tests);
}
// Tokens without any letters
TEST(CleanToken, Empty) {
map<string, set<string>> tests;
tests[""].insert("23432423");
tests[""].insert("2343098765432345678998765434567892423");
tests[""].insert("....$$$$......");
tests[""].insert("....2312^#@@@....");
tests[""].insert("");
testCleanToken(tests);
}
// Tokens with uppercase letters and punctuation
TEST(CleanToken, Uppercase) {
map<string, set<string>> tests;
tests["hello"].insert("HELLO.");
tests["hello"].insert("heLlo...");
tests["hello"].insert("hellO.\"!?");
tests["hello"].insert(".HELLO");
tests["hello"].insert("...Hello");
tests["hello"].insert(".\"!?heLLo");
testCleanToken(tests);
}