Просмотр исходного кода

Issue #253: Make the sort test more generic. This to allow a broader range of implementations. Currently users are hindered into return the type HashMap<Integer, List<String>. This test update will check the order of any Map that maps to any Collection value type. This opens the doors for more possible types of solutions. (#269)

Dave Thomas 9 лет назад
Родитель
Сommit
2867d445c4

+ 1
- 0
exercises/grade-school/build.gradle Просмотреть файл

@@ -7,6 +7,7 @@ repositories {
7 7
 }
8 8
 
9 9
 dependencies {
10
+  testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
10 11
   testCompile "junit:junit:4.12"
11 12
 }
12 13
 test {

+ 17
- 8
exercises/grade-school/src/test/java/SchoolTest.java Просмотреть файл

@@ -1,11 +1,12 @@
1 1
 import org.junit.Ignore;
2 2
 import org.junit.Test;
3 3
 
4
-import java.util.Arrays;
4
+import java.util.Collection;
5 5
 import java.util.HashMap;
6
-import java.util.List;
7 6
 import java.util.Map;
8 7
 
8
+import org.hamcrest.Matcher;
9
+import static org.hamcrest.collection.IsIterableContainingInOrder.*;
9 10
 import static org.hamcrest.CoreMatchers.*;
10 11
 import static org.junit.Assert.*;
11 12
 
@@ -69,14 +70,22 @@ public class SchoolTest {
69 70
   @Ignore
70 71
   @Test
71 72
   public void sortsSchool() {
73
+    school.add("Kyle", 4);
74
+    school.add("Zed", 4);
75
+    school.add("Adam", 4);
72 76
     school.add("Jennifer", 4);
73 77
     school.add("Kareem", 6);
74 78
     school.add("Christopher", 4);
75
-    school.add("Kyle", 3);
76
-    Map<Integer, List<String>> sortedStudents = new HashMap<Integer, List<String>>();
77
-    sortedStudents.put(6, Arrays.asList("Kareem"));
78
-    sortedStudents.put(4, Arrays.asList("Christopher", "Jennifer"));
79
-    sortedStudents.put(3, Arrays.asList("Kyle"));
80
-    assertEquals(school.sort(), sortedStudents);
79
+    school.add("Kylie", 3);
80
+    Map<Integer, Matcher> sortedStudents = new HashMap<Integer, Matcher>();
81
+    sortedStudents.put(6, contains("Kareem"));
82
+    sortedStudents.put(4, contains("Adam", "Christopher", "Jennifer", "Kyle", "Zed"));
83
+    sortedStudents.put(3, contains("Kylie"));
84
+
85
+    Map schoolStudents = school.sort();
86
+    for (Map.Entry<?, Matcher> entry : sortedStudents.entrySet()) {
87
+
88
+      assertThat((Collection) schoolStudents.get(entry.getKey()), entry.getValue());
89
+    }
81 90
   }
82 91
 }