Repository navigation
Expand file tree
/
Copy pathBackendDeveloperTests.java
More file actions
270 lines (223 loc) · 9.25 KB
/
Copy pathBackendDeveloperTests.java
File metadata and controls
270 lines (223 loc) · 9.25 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
// -== CS400 Spring 2024 File Header Information ==-
// Name:Saksham Dhuria
// Email: sdhuria@wisc.edu
// Lecturer: Gary Dahl
// Notes to Grader: i didnt end up hating this as much i prob was thinking i would cool but some unclear instructions ty fun project though
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.io.IOException;
import java.util.Iterator;
import java.util.Scanner;
public class BackendDeveloperTests{
/*
my first test to check that the readData worked!
*/
@Test
public void testOne(){
IterableSortedCollection<SongInterface> placeholderTree = new ISCPlaceholder<>();
Backend bp = new Backend(placeholderTree);
try{
bp.readData("songs.csv");
Assertions.assertNotNull(placeholderTree);
} catch (IOException e){
}
}
/*
my second test to check that after read data we are able to getrange with bad input that should not give anything also a cool thing we wont be using filteroldsongs
*/
@Test
public void testTwo(){
IterableSortedCollection<SongInterface> placeholderTree = new ISCPlaceholder<>();
Backend bp = new Backend(placeholderTree);
try{
bp.readData("songs.csv");
} catch (IOException e){
}
Assertions.assertEquals(1, bp.getRange(0, 0).size());
}
/*
my third test to check a similar thing where i dont use the filter and testPlaceHolder for a more valid input
*/
@Test
public void testThree(){
IterableSortedCollection<SongInterface> placeholderTree = new ISCPlaceholder<>();
Backend bp = new Backend(placeholderTree);
try{
bp.readData("songs.csv");
} catch (IOException e){
}
Assertions.assertEquals(12, bp.getRange(97, 98).size());
Assertions.assertIterableEquals(List.of("\"Hey Soul Sister\"", "Muny - Album Version (Edited)","Boyfriend", "Same Old Love", "Scars To Your Beautiful", "I Got You", "Behind Your Back", "IDGAF", "Wild Thoughts (feat. Rihanna & Bryson Tiller)", "Say Something", "Filthy", "South of the Border (feat. Camila Cabello & Cardi B)" ), bp.getRange(97, 98));
}
/*
my fourth test to check the similar thing but this time we have after filter
*/
@Test
public void testFour(){
IterableSortedCollection<SongInterface> placeholderTree = new ISCPlaceholder<>();
Backend bp = new Backend(placeholderTree);
try{
bp.readData("songs.csv");
} catch (IOException e){
}
bp.getRange(97, 98);
Assertions.assertEquals(List.of("\"Hey Soul Sister\"", "Muny - Album Version (Edited)","Boyfriend"), bp.filterOldSongs(2012));
}
/*
my fifth test to check the five most dancable based on the 97, 98 call and also after filter
*/
@Test
public void testFive(){
IterableSortedCollection<SongInterface> placeholderTree = new ISCPlaceholder<>();
Backend bp = new Backend(placeholderTree);
try{
bp.readData("songs.csv");
} catch (IOException e){
}
bp.getRange(97, 98);
bp.filterOldSongs(2012);
Assertions.assertEquals(3, bp.fiveMostDanceable().size());
Assertions.assertEquals(List.of("67: \"Hey Soul Sister\"", "72: Boyfriend", "80: Muny - Album Version (Edited)"), bp.fiveMostDanceable());
}
/*
integration testers #1 where i am just trying to check for interaction with frontend for the bpm to above but here i am actually listing out what the specified sogn should be
*/
@Test
public void testIntegrationBPM() {
//creating the backend instance of the object
IterableSortedCollection<SongInterface> tr = new ISCPlaceholder<>();
BackendInterface bd = new Backend(tr);
//scanner object
Scanner scn;
//creating a tester object
TextUITester tstr;
String rslt;
//Frontend Object
FrontendInterface fd;
//First thing is getting a file read
tstr = new TextUITester("R\nsongs.csv\nQ\n");
scn = new Scanner(System.in);
fd = new FrontendImplementations(bd, scn);
fd.runCommandLoop();
rslt = tstr.checkOutput();
Assertions.assertTrue(rslt.contains("File read successfully."));
scn.close();
//second part of this is to check if i input for commang G 180-180 is that gonna be correct
tstr= new TextUITester("G\n180\n180\nQ\n");
scn = new Scanner(System.in);
fd = new FrontendImplementations(bd, scn);
fd.runCommandLoop();
rslt=tstr.checkOutput();
Assertions.assertTrue(rslt.contains("Roar"));
Assertions.assertTrue(rslt.contains("Dusk Till Dawn - Radio Edit"));
scn.close();
}
/*
integration testers #2 where i am checking the FilterOld Songs
*/
@Test
public void testFilterBPM() {
//creating the backend instance of the object
IterableSortedCollection<SongInterface> tr = new ISCPlaceholder<>();
BackendInterface bd = new Backend(tr);
//scanner object
Scanner scn;
//creating a tester object
TextUITester tstr;
String rslt;
//Frontend Object
FrontendInterface fd;
//First thing is getting a file read
tstr = new TextUITester("R\nsongs.csv\nQ\n");
scn = new Scanner(System.in);
fd = new FrontendImplementations(bd, scn);
fd.runCommandLoop();
rslt = tstr.checkOutput();
Assertions.assertTrue(rslt.contains("File read successfully."));
scn.close();
//second part of this is to check if i input for commang G 180-180 is that gonna be correct
tstr= new TextUITester("G\n180\n180\nQ\n");
scn = new Scanner(System.in);
fd = new FrontendImplementations(bd, scn);
fd.runCommandLoop();
rslt=tstr.checkOutput();
Assertions.assertTrue(rslt.contains("Roar"));
Assertions.assertTrue(rslt.contains("Dusk Till Dawn - Radio Edit"));
scn.close();
//now i am going to test for filter of lets say 2015
tstr= new TextUITester("F\n2015\nQ\n");
scn = new Scanner(System.in);
fd = new FrontendImplementations(bd,scn);
Assertions.assertTrue(rslt.contains("Roar"));
scn.close();
}
/*
partner test i am just checking a false read of the file
*/
@Test
public void testPartnerREAD() {
//creating the backend instance of the object
IterableSortedCollection<SongInterface> tr = new ISCPlaceholder<>();
BackendInterface bd = new Backend(tr);
//scanner object
Scanner scn;
//creating a tester object
TextUITester tstr;
String rslt;
//Frontend Object
FrontendInterface fd;
//First thing is getting a file read
tstr = new TextUITester("R\nsong\nQ\n");
scn = new Scanner(System.in);
fd = new FrontendImplementations(bd, scn);
fd.runCommandLoop();
rslt = tstr.checkOutput();
Assertions.assertTrue(rslt.contains("Error reading file:"));
scn.close();
}
/*
partner test i am just checking a false call at Top 5
*/
@Test
public void testPartnerTop5() {
//creating the backend instance of the object
IterableSortedCollection<SongInterface> tr = new ISCPlaceholder<>();
BackendInterface bd = new Backend(tr);
//scanner object
Scanner scn;
//creating a tester object
TextUITester tstr;
String rslt;
//Frontend Object
FrontendInterface fd;
//First thing is getting a file read
tstr = new TextUITester("R\nsongs.csv\nQ\n");
scn = new Scanner(System.in);
fd = new FrontendImplementations(bd, scn);
fd.runCommandLoop();
rslt = tstr.checkOutput();
Assertions.assertTrue(rslt.contains("File read successfully."));
scn.close();
//second part of this is to check if i input for commang G 180-180 is that gonna be correct
tstr= new TextUITester("G\n180\n180\nQ\n");
scn = new Scanner(System.in);
fd = new FrontendImplementations(bd, scn);
fd.runCommandLoop();
rslt=tstr.checkOutput();
Assertions.assertTrue(rslt.contains("Roar"));
Assertions.assertTrue(rslt.contains("Dusk Till Dawn - Radio Edit"));
scn.close();
//now i am going to test for filter of lets say 2015
tstr= new TextUITester("F\n2015\nQ\n");
scn = new Scanner(System.in);
fd = new FrontendImplementations(bd,scn);
Assertions.assertTrue(rslt.contains("Roar"));
scn.close();
//finally calling D command
tstr = new TextUITester("D\nQ\n");
scn = new Scanner(System.in);
fd = new FrontendImplementations(bd, scn);
scn.close();
}
}