/
SearchOutputTest.java
190 lines (168 loc) · 4.95 KB
/
SearchOutputTest.java
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import java.nio.file.Path;
import java.time.Duration;
import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
/**
* JUnit tests for the inverted index search functionality.
*
* @author CS 212 Software Development
* @author University of San Francisco
* @version Fall 2020
*/
@TestMethodOrder(Alphanumeric.class)
public class SearchOutputTest extends TestUtilities {
/** Amount of time to wait for an individual test to finish. */
public static final Duration TIMEOUT = Duration.ofMinutes(1);
/**
* Generates the arguments to use for this test case. Designed to be used
* inside a JUnit test.
*
* @param subdir the output subdirectory to use
* @param input the input path to use
* @param query the query file to use for search
* @param exact whether to perform exact or partial search
*/
public static void test(String subdir, Path input, String query, boolean exact) {
String type = exact ? "exact" : "partial";
String prefix = "search-" + type;
String filename = outputFileName(prefix, input);
Path actual = Paths.ACTUAL.path.resolve(filename).normalize();
Path expected = Paths.EXPECTED.path.resolve("search").resolve(subdir).resolve(filename).normalize();
String[] args = {
Flags.PATH.text, input.normalize().toString(),
Flags.QUERY.text, Paths.QUERY.path.resolve(query).toString(),
Flags.RESULTS.text, actual.normalize().toString(),
exact ? Flags.EXACT.text : ""
};
checkOutput(args, actual, expected);
}
/**
* Junit tests for the search results output for exact search.
*/
@Nested
@TestMethodOrder(OrderAnnotation.class)
public class A_ExactSearchTest {
/** The default subdir for this nested class. */
public final String subdir = "exact";
/** The default search mode for this nested class. */
public final boolean exact = true;
/**
* Tests the search result output for the simple directory.
*/
@Order(1)
@Test
public void testSimpleDirectory() {
Path input = Paths.TEXT.path.resolve("simple");
String query = "simple.txt";
test(subdir, input, query, exact);
}
/**
* Tests the search result output for the rfcs subdirectory.
*/
@Order(2)
@Test
public void testRfcDirectory() {
Path input = Paths.TEXT.path.resolve("rfcs");
String query = "letters.txt";
test(subdir, input, query, exact);
}
/**
* Tests the search result output for files in the guten subdirectory.
*
* @param filename filename of a text file in the guten subdirectory
*/
@Order(3)
@ParameterizedTest
@ValueSource(strings = {
"50468-0.txt",
"pg37134.txt",
"pg22577.txt",
"pg1661.txt",
"pg1322.txt",
"pg1228.txt",
"1400-0.txt"
})
public void testGutenFiles(String filename) {
Path input = Paths.TEXT.path.resolve("guten").resolve(filename);
String query = "letters.txt";
test(subdir, input, query, exact);
}
/**
* Tests the search result output for the guten subdirectory.
*/
@Order(4)
@Test
public void testGutenDirectory() {
Path input = Paths.TEXT.path.resolve("guten");
String query = "letters.txt";
test(subdir, input, query, exact);
}
/**
* Tests the search result output for the guten subdirectory.
*/
@Order(5)
@Test
public void testTextDirectory() {
Path input = Paths.TEXT.path;
String query = "complex.txt";
test(subdir, input, query, exact);
}
}
/**
* Junit tests for the search results output for partial search.
*/
@Nested
@TestMethodOrder(OrderAnnotation.class)
public class B_PartialSearchTest {
/** The default subdir for this nested class. */
public final String subdir = "partial";
/** The default search mode for this nested class. */
public final boolean exact = false;
/**
* Tests the search result output for the simple directory.
*/
@Order(1)
@Test
public void testSimpleDirectory() {
Path input = Paths.TEXT.path.resolve("simple");
String query = "simple.txt";
test(subdir, input, query, exact);
}
/**
* Tests the search result output for the rfcs subdirectory.
*/
@Order(2)
@Test
public void testRfcDirectory() {
Path input = Paths.TEXT.path.resolve("rfcs");
String query = "letters.txt";
test(subdir, input, query, exact);
}
/**
* Tests the search result output for the guten subdirectory.
*/
@Order(3)
@Test
public void testGutenDirectory() {
Path input = Paths.TEXT.path.resolve("guten");
String query = "letters.txt";
test(subdir, input, query, exact);
}
/**
* Tests the search result output for the text subdirectory.
*/
@Order(4)
@Test
public void testTextDirectory() {
Path input = Paths.TEXT.path;
String query = "complex.txt";
test(subdir, input, query, exact);
}
}
}