-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackendDeveloper_Tests.java
More file actions
315 lines (262 loc) · 11.2 KB
/
BackendDeveloper_Tests.java
File metadata and controls
315 lines (262 loc) · 11.2 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// --== CS400 Project One File Header ==--
// Name: Jeonghyeon Park
// CSL Username: jeonghyeon
// Email: jpark634@wisc.edu
// Lecture #: COMPSCI400: Programming III (001) SP23, TH @ 1:00PM
// Notes to Grader: none
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Scanner;
public class BackendDeveloper_Tests {
//Test if findPostsByTitleWords() method works properly
public static boolean test1() {
//create objects
HashtableWithDuplicateKeysBD <String, PostInterface> hashtable = new HashtableWithDuplicateKeysBD();
PostReaderBD postReader = new PostReaderBD();
CHSearchBackendBD backend = new CHSearchBackendBD(hashtable,postReader);
//load data
try {
backend.loadData("file.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
//post by title words
List <String> postTitle = backend.findPostsByTitleWords("the");
if (!postTitle.get(0).equals("TITLE: The Old Man and The Sea\n"
+ "BODY: It is about the old man and the sea\n"
+ "URL: www.google.com\n")) {
return false;
}
if (!postTitle.get(1).equals("TITLE: The Beauty and the Beast\n"
+ "BODY: They loved each other\n"
+ "URL: www.google.com\n")) {
return false;
}
if (!postTitle.get(2).equals("TITLE: The Great grandparents\n"
+ "BODY: Life is boring\n"
+ "URL: www.naver.com\n")) {
return false;
}
return true;
}
//Test if findPostsByBodyWords() method works properly
public static boolean test2() {
HashtableWithDuplicateKeysBD <String, PostInterface> hashtable = new HashtableWithDuplicateKeysBD();
PostReaderBD postReader = new PostReaderBD();
CHSearchBackendBD backend = new CHSearchBackendBD(hashtable,postReader);
try {
backend.loadData("file.txt");
}
catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
//post by body words
List <String> postBody = backend.findPostsByBodyWords("love");
if (!postBody.get(0).equals("TITLE: Sleeping Beauty\n"
+ "BODY: sleeping beauty loved the old man\n"
+ "URL: www.naver.com\n")) {
return false;
}
if (!postBody.get(1).equals("TITLE: Toy Story\n"
+ "BODY: It is the story about a man that loved toy\n"
+ "URL: www.daum.net\n")) {
return false;
}
if (!postBody.get(2).equals("TITLE: The Beauty and the Beast\n"
+ "BODY: They loved each other\n"
+ "URL: www.google.com\n")) {
return false;
}
return true;
}
//Test if findPostsByTitleOrBodyWords() method works properly
public static boolean test3() {
HashtableWithDuplicateKeysBD <String, PostInterface> hashtable = new HashtableWithDuplicateKeysBD();
PostReaderBD postReader = new PostReaderBD();
CHSearchBackendBD backend = new CHSearchBackendBD(hashtable,postReader);
try {
backend.loadData("file.txt");
}
catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
//post by both title and body words
List <String> postBoth = backend.findPostsByTitleOrBodyWords("man");
if (!postBoth.get(0).equals("TITLE: The Old Man and The Sea\n"
+ "BODY: It is about the old man and the sea\n"
+ "URL: www.google.com\n")){
return false;
}
return true;
}
//Test if getStatisticsString() method works properly
public static boolean test4() {
HashtableWithDuplicateKeysBD <String, PostInterface> hashtable = new HashtableWithDuplicateKeysBD();
PostReaderBD postReader = new PostReaderBD();
CHSearchBackendBD backend = new CHSearchBackendBD(hashtable,postReader);
try {
backend.loadData("file.txt");
}
catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
//for the purpose of loading posts
List <String> postTitle = backend.findPostsByTitleWords("the");
if (!backend.getStatisticsString().equals( "POST FOUND: \n"
+ "[TITLE: The Old Man and The Sea\n"
+ "BODY: It is about the old man and the sea\n"
+ "URL: www.google.com\n"
+ ", TITLE: The Beauty and the Beast\n"
+ "BODY: They loved each other\n"
+ "URL: www.google.com\n"
+ ", TITLE: The Great grandparents\n"
+ "BODY: Life is boring\n"
+ "URL: www.naver.com\n"
+ "]")){
return false;
}
return true;
}
//Test if it throws FileNotFoundException when the filename is null
public static boolean test5() {
HashtableWithDuplicateKeysBD <String, PostInterface> hashtable = new HashtableWithDuplicateKeysBD();
PostReaderBD postReader = new PostReaderBD();
CHSearchBackendBD backend = new CHSearchBackendBD(hashtable,postReader);
try {
backend.loadData(null);
} catch (FileNotFoundException e) {//<------------HERE
return true;//if it throws the exception, return true
}
return false;
}
//tests load data of front end role, false if malfunction
public static boolean test6() {
PostReaderInterface reader = new PostReaderDW();
HashtableWithDuplicateKeysInterface<String, PostInterface> hashT = new HashtableWithDuplicateKeysAE<String, PostInterface>();
CHSearchBackendBD backend =new CHSearchBackendBD(hashT,reader);
TextUITester tester = new TextUITester("L\ndata/large.txt\nQ\n");
try (Scanner scan = new Scanner(System.in)) {
CHSearchFrontendFD frontTest1 = new CHSearchFrontendFD(scan, backend);
frontTest1.runCommandLoop();
String output = tester.checkOutput();
if (!output.contains("Choose a command from the list below:") &&
!output.contains(" [L]oad data from file") &&
!output.contains(" Search Post [T]itles") &&
!output.contains(" Search Post [B]odies") &&
!output.contains(" Search [P]ost titles and bodies") &&
!output.contains(" Display [S]tatistics for dataset") &&
!output.contains(" [Q]uit") &&
!output.contains("Enter the name of the file to load: ")&&
!output.contains("Thank you for using the Cheap and Healthy Search App.")) {
return false;
}
} catch (Exception e) {
return false;
}
return true;
}
//tests load data of front end role, false if malfunction
public static boolean test7() {
PostReaderInterface reader = new PostReaderDW();
HashtableWithDuplicateKeysInterface<String, PostInterface> hashT = new HashtableWithDuplicateKeysAE<String, PostInterface>();
CHSearchBackendBD backend =new CHSearchBackendBD(hashT,reader);
TextUITester tester = new TextUITester("L\n1.txt\nQ\n");
try (Scanner scan = new Scanner(System.in)) {
CHSearchFrontendFD frontTest3 = new CHSearchFrontendFD(scan, backend);
frontTest3.runCommandLoop();
String output = tester.checkOutput();
if (!output.contains("Choose a command from the list below:") &&
!output.contains(" [L]oad data from file") &&
!output.contains(" Search Post [T]itles") &&
!output.contains(" Search Post [B]odies") &&
!output.contains(" Search [P]ost titles and bodies") &&
!output.contains(" Display [S]tatistics for dataset") &&
!output.contains(" [Q]uit")&&
!output.contains("Enter the name of the file to load: ") &&
!output.contains("Error: Could not find or load file: 1.txt")&&
!output.contains("Thank you for using the Cheap and Healthy Search App.")) {
return false;
}
}
catch (Exception e) {
return false;
}
return true;
}
//tests integration is well functioning. testing find title
public static boolean test8() {
PostReaderInterface reader = new PostReaderDW();
HashtableWithDuplicateKeysInterface<String, PostInterface> hashT = new HashtableWithDuplicateKeysAE<String, PostInterface>();
CHSearchBackendBD back = new CHSearchBackendBD(hashT,reader);
try {
back.loadData("data/fake.txt");
back.loadData("data/large.txt");
back.loadData("data/small.txt");
}
catch(FileNotFoundException e){
e.printStackTrace();
return false;
}
TextUITester uiTester = new TextUITester("T\nQuick\nN\nQ\n");
Scanner scan = new Scanner(System.in);
CHSearchFrontendFD front = new CHSearchFrontendFD(scan, back);
// front.runCommandLoop();
String systemOutput = uiTester.checkOutput();
if(!systemOutput.contains("Quick, easy, high calorie meals?!")
&&!systemOutput.contains("https://www.reddit.com/r/EatCheapAndHealthy/comments/zofez7/quick_easy_high_calorie_meals/")
&&!systemOutput.contains("I'm going through a hard time of struggling to eat & prep good meals.")
&&!systemOutput.contains("Title with \"[Quick]\" being searched.")
&&!systemOutput.contains("Choose the option\nL - Load data from file\n")
&&!systemOutput.contains("T - Search Post Titles\nB-Search Post Bodies\n")
&&!systemOutput.contains("P - Search Post titles and bodies\n")
&&!systemOutput.contains("S - Display Statistics for dataset\nQ - Quit")) {
}
return true;
}
//tests integration is well functioning. testing find body
public static boolean test9(){
PostReaderInterface reader = new PostReaderDW();
HashtableWithDuplicateKeysInterface<String, PostInterface> hashT = new HashtableWithDuplicateKeysAE<String, PostInterface>();
CHSearchBackendBD back = new CHSearchBackendBD(hashT,reader);
try {
back.loadData("data/fake.txt");
back.loadData("data/large.txt");
back.loadData("data/small.txt");
}
catch(FileNotFoundException e){
e.printStackTrace();
return false;
}
TextUITester uiTester = new TextUITester("B\npouched\nN\nQ\n");
Scanner scan = new Scanner(System.in);
CHSearchFrontendFD front = new CHSearchFrontendFD(scan, back);
// front.runCommandLoop();
String systemOutput = uiTester.checkOutput();
if(!systemOutput.contains("Is there any good way to compare canned and pouched tuna for price?")
&&!systemOutput.contains("https://www.reddit.com/r/EatCheapAndHealthy/comments/zod0s8/is_tuna_in_the_can_or_pouch_generally_cheaper/")
&&!systemOutput.contains("Usually I buy the cheapest tuna I can")
&&!systemOutput.contains("Body with \"[pouched]\" being searched.")
&&!systemOutput.contains("Choose the option\nL - Load data from file\n")
&&!systemOutput.contains("T - Search Post Titles\nB-Search Post Bodies\n")
&&!systemOutput.contains("P - Search Post titles and bodies\n")
&&!systemOutput.contains("S - Display Statistics for dataset\nQ - Quit")) {
}
return true;
}
public static void main(String[] args) {
System.out.println("Individual Test 1 passed: " + test1());
System.out.println("Individual Test 2 passed: " + test2());
System.out.println("Individual Test 3 passed: " + test3());
System.out.println("Individual Test 4 passed: " + test4());
System.out.println("Individual Test 5 passed: " + test5());
System.out.println("FrontEnd Test 1 passed: " + test6());
System.out.println("FrontEnd Test 2 passed: " + test7());
System.out.println("Integration Test 1 passed: " + test8());
System.out.println("Integration Test 2 passed: " + test9());
}
}