-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_query_matches.h
92 lines (67 loc) · 2.52 KB
/
find_query_matches.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
88
89
90
91
92
#include <gtest/gtest.h>
#include <map>
#include <set>
#include <string>
#include "search.h"
using namespace std;
map<string, set<string>> INDEX = {
{"hello", {"example.com", "uic.edu"}},
{"there", {"example.com"}},
{"according", {"uic.edu"}},
{"to", {"uic.edu"}},
{"all", {"example.com", "uic.edu", "random.org"}},
{"known", {"uic.edu"}},
{"laws", {"random.org"}},
{"of", {"random.org"}},
{"aviation", {"random.org"}},
{"a", {"uic.edu", "random.org"}},
};
TEST(FindQueryMatches, SingleTerm) {
set<string> expected;
expected = {"example.com"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "there"));
expected = {"example.com", "uic.edu"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "hello"));
EXPECT_EQ(expected, findQueryMatches(INDEX, "Hello!"));
}
TEST(FindQueryMatches, Union) {
set<string> expected;
expected = {"uic.edu"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "known to"));
expected = {"example.com", "uic.edu", "random.org"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "hello laws aviation"));
EXPECT_EQ(expected, findQueryMatches(INDEX, "Hello, Laws, AVIATION!"));
}
TEST(FindQueryMatches, Intersection) {
set<string> expected;
expected = {"example.com"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "all +there"));
expected = {"example.com", "uic.edu"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "hello +all"));
expected = {"uic.edu"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "hello +all +to"));
expected = {};
EXPECT_EQ(expected, findQueryMatches(INDEX, "hello +aviation"));
}
TEST(FindQueryMatches, Difference) {
set<string> expected;
expected = {"example.com", "uic.edu"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "all -laws"));
expected = {"random.org"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "all -hello"));
expected = {"example.com"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "all -of -a"));
expected = {};
EXPECT_EQ(expected, findQueryMatches(INDEX, "known -to"));
expected = {};
EXPECT_EQ(expected, findQueryMatches(INDEX, "to -all -a"));
}
TEST(FindQueryMatches, LongCombinedQueries) {
set<string> expected;
expected = {"example.com"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "there laws aviation -to +hello"));
expected = {};
EXPECT_EQ(expected, findQueryMatches(INDEX, "all -all +all"));
expected = {"example.com", "uic.edu", "random.org"};
EXPECT_EQ(expected, findQueryMatches(INDEX, "all -all +all all"));
}