Leon 6 lat temu
rodzic
commit
c69b6acfb1

+ 122
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/GetStudyMapTest.java Wyświetl plik

14
  */
14
  */
15
 public class GetStudyMapTest {
15
 public class GetStudyMapTest {
16
     @Test
16
     @Test
17
+    public void test0() {
18
+        // given
19
+        ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
20
+        Student expectedStudent1 = new Student();
21
+        Double expectedStudyTime1 = 0.0;
22
+        expectedStudent1.learn(expectedStudyTime1);
23
+        zipCodeWilmington.enroll(expectedStudent1);
24
+
25
+
26
+
27
+        // when
28
+        Map<Student, Double> studyMap = zipCodeWilmington.getStudyMap();
29
+        List<Map.Entry<Student, Double>> entrySet = new ArrayList<>(studyMap.entrySet());
30
+        Map.Entry<Student, Double> firstEntry = entrySet.get(0);
31
+
32
+        Student actualStudent1 = firstEntry.getKey();
33
+        Double actualStudyTime1 = firstEntry.getValue();
34
+
35
+
36
+
37
+        // then
38
+        Assert.assertEquals(expectedStudent1, actualStudent1);
39
+        Assert.assertEquals(expectedStudyTime1, actualStudyTime1);
40
+    }
41
+
42
+    @Test
17
     public void test1() {
43
     public void test1() {
18
         // given
44
         // given
19
         ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
45
         ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
130
         Assert.assertEquals(expectedStudent3, actualStudent3);
156
         Assert.assertEquals(expectedStudent3, actualStudent3);
131
         Assert.assertEquals(expectedStudyTime3, actualStudyTime3);
157
         Assert.assertEquals(expectedStudyTime3, actualStudyTime3);
132
     }
158
     }
159
+
160
+
161
+
162
+
163
+    @Test
164
+    public void test4() {
165
+        // given
166
+        ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
167
+        Student expectedStudent1 = new Student(3);
168
+        Student expectedStudent2 = new Student(4);
169
+        Student expectedStudent3 = new Student(5);
170
+
171
+        zipCodeWilmington.enroll(expectedStudent1);
172
+        zipCodeWilmington.enroll(expectedStudent2);
173
+        zipCodeWilmington.enroll(expectedStudent3);
174
+
175
+        Double expectedStudyTime1 = 500.0;
176
+        Double expectedStudyTime2 = 1000.0;
177
+        Double expectedStudyTime3 = 2000.0;
178
+
179
+        expectedStudent1.learn(expectedStudyTime1);
180
+        expectedStudent2.learn(expectedStudyTime2);
181
+        expectedStudent3.learn(expectedStudyTime3);
182
+
183
+
184
+
185
+        // when
186
+        Map<Student, Double> studyMap = zipCodeWilmington.getStudyMap();
187
+        List<Map.Entry<Student, Double>> entrySet = new ArrayList<>(studyMap.entrySet());
188
+        Map.Entry<Student, Double> firstEntry = entrySet.get(0);
189
+        Map.Entry<Student, Double> secondEntry = entrySet.get(1);
190
+        Map.Entry<Student, Double> thirdEntry = entrySet.get(2);
191
+
192
+        Student actualStudent1 = firstEntry.getKey();
193
+        Student actualStudent2 = secondEntry.getKey();
194
+        Student actualStudent3 = thirdEntry.getKey();
195
+
196
+        Double actualStudyTime1 = firstEntry.getValue();
197
+        Double actualStudyTime2 = secondEntry.getValue();
198
+        Double actualStudyTime3 = thirdEntry.getValue();
199
+
200
+
201
+
202
+        // then
203
+        Assert.assertEquals(expectedStudent1, actualStudent1);
204
+        Assert.assertEquals(expectedStudyTime1, actualStudyTime1);
205
+
206
+
207
+        Assert.assertEquals(expectedStudent2, actualStudent2);
208
+        Assert.assertEquals(expectedStudyTime2, actualStudyTime2);
209
+
210
+
211
+        Assert.assertEquals(expectedStudent3, actualStudent3);
212
+        Assert.assertEquals(expectedStudyTime3, actualStudyTime3);
213
+    }
214
+
215
+    @Test
216
+    public void test5() {
217
+        // given
218
+        ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
219
+        Student expectedStudent1 = new Student(3);
220
+        Student expectedStudent2 = new Student(4);
221
+
222
+        zipCodeWilmington.enroll(expectedStudent1);
223
+        zipCodeWilmington.enroll(expectedStudent2);
224
+
225
+        Double expectedStudyTime1 = 500.0;
226
+        Double expectedStudyTime2 = 1000.0;
227
+
228
+        expectedStudent1.learn(expectedStudyTime1);
229
+        expectedStudent2.learn(expectedStudyTime2);
230
+
231
+
232
+
233
+        // when
234
+        Map<Student, Double> studyMap = zipCodeWilmington.getStudyMap();
235
+        List<Map.Entry<Student, Double>> entrySet = new ArrayList<>(studyMap.entrySet());
236
+        Map.Entry<Student, Double> firstEntry = entrySet.get(0);
237
+        Map.Entry<Student, Double> secondEntry = entrySet.get(1);
238
+
239
+        Student actualStudent1 = firstEntry.getKey();
240
+        Student actualStudent2 = secondEntry.getKey();
241
+
242
+        Double actualStudyTime1 = firstEntry.getValue();
243
+        Double actualStudyTime2 = secondEntry.getValue();
244
+
245
+
246
+
247
+        // then
248
+        Assert.assertEquals(expectedStudent1, actualStudent1);
249
+        Assert.assertEquals(expectedStudyTime1, actualStudyTime1);
250
+
251
+
252
+        Assert.assertEquals(expectedStudent2, actualStudent2);
253
+        Assert.assertEquals(expectedStudyTime2, actualStudyTime2);
254
+    }
133
 }
255
 }

+ 32
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/LectureTest.java Wyświetl plik

30
                 new Student());
30
                 new Student());
31
     }
31
     }
32
 
32
 
33
+
34
+    @Test
35
+    public void test4() {
36
+        test(50.0,
37
+                new Student(),
38
+                new Student(),
39
+                new Student(),
40
+                new Student());
41
+    }
42
+
43
+    @Test
44
+    public void test5() {
45
+        test(25.0,
46
+                new Student(),
47
+                new Student(),
48
+                new Student(),
49
+                new Student(),
50
+                new Student());
51
+    }
52
+
53
+
54
+    @Test
55
+    public void test6() {
56
+        test(12.5,
57
+                new Student(),
58
+                new Student(),
59
+                new Student(),
60
+                new Student(),
61
+                new Student(),
62
+                new Student());
63
+    }
64
+
33
     public void test(Double lectureTime, Student... students) {
65
     public void test(Double lectureTime, Student... students) {
34
         // given
66
         // given
35
         ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
67
         ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();