소스 검색

Merge pull request #526 from Smarticles101/kindergarten-garden

kindergarten-garden: add to track
FridaTveit 9 년 전
부모
커밋
7ca97c4ad2

+ 5
- 0
config.json 파일 보기

324
       "slug": "run-length-encoding",
324
       "slug": "run-length-encoding",
325
       "difficulty": 1,
325
       "difficulty": 1,
326
       "topics": []
326
       "topics": []
327
+    },
328
+    {
329
+      "slug": "kindergarten-garden",
330
+      "difficulty": 1,
331
+      "topics": []
327
     }
332
     }
328
   ],
333
   ],
329
   "deprecated": [
334
   "deprecated": [

+ 17
- 0
exercises/kindergarten-garden/build.gradle 파일 보기

1
+apply plugin: "java"
2
+apply plugin: "eclipse"
3
+apply plugin: "idea"
4
+
5
+repositories {
6
+    mavenCentral()
7
+}
8
+
9
+dependencies {
10
+    testCompile "junit:junit:4.12"
11
+}
12
+test {
13
+    testLogging {
14
+        exceptionFormat = 'full'
15
+        events = ["passed", "failed", "skipped"]
16
+    }
17
+}

+ 44
- 0
exercises/kindergarten-garden/src/example/java/KindergartenGarden.java 파일 보기

1
+import java.util.Arrays;
2
+import java.util.List;
3
+import java.util.ArrayList;
4
+
5
+
6
+public class KindergartenGarden {
7
+    private String[] students;
8
+    private String garden;
9
+    private static final int PLANTS_PER_STUDENT_PER_ROW = 2;
10
+    private final int newRowLocation;
11
+
12
+    private static final String[] DEFAULT_STUDENTS = {
13
+            "Alice", "Bob", "Charlie", "David",
14
+            "Eve", "Fred", "Ginny", "Harriet",
15
+            "Ileana", "Joseph", "Kincaid", "Larry"
16
+    };
17
+
18
+    public KindergartenGarden(String garden, String[] students) {
19
+        this.garden = garden;
20
+        Arrays.sort(students);
21
+        this.students = students;
22
+        newRowLocation = garden.indexOf('\n') + 1;
23
+    }
24
+
25
+    public KindergartenGarden(String garden) {
26
+        this(garden, DEFAULT_STUDENTS);
27
+    }
28
+
29
+    public List<Plant> getPlantsOfStudent(String student) {
30
+        List<Plant> plants = new ArrayList<Plant>();
31
+        int studentPlantsIndex = Arrays.binarySearch(students, student) * PLANTS_PER_STUDENT_PER_ROW;
32
+
33
+        for (int i = studentPlantsIndex; i < studentPlantsIndex + PLANTS_PER_STUDENT_PER_ROW; i++) {
34
+            plants.add(Plant.getPlant(garden.charAt(i)));
35
+        }
36
+
37
+        for (int i = newRowLocation + studentPlantsIndex;
38
+             i < newRowLocation + studentPlantsIndex + PLANTS_PER_STUDENT_PER_ROW; i++) {
39
+            plants.add(Plant.getPlant(garden.charAt(i)));
40
+        }
41
+
42
+        return plants;
43
+    }
44
+}

+ 21
- 0
exercises/kindergarten-garden/src/example/java/Plant.java 파일 보기

1
+public enum Plant {
2
+    VIOLETS,
3
+    RADISHES,
4
+    CLOVER,
5
+    GRASS;
6
+
7
+    public static Plant getPlant(char plantCode) {
8
+        switch (plantCode) {
9
+            case 'G':
10
+                return GRASS;
11
+            case 'C':
12
+                return CLOVER;
13
+            case 'R':
14
+                return RADISHES;
15
+            case 'V':
16
+                return VIOLETS;
17
+        }
18
+
19
+        return null;
20
+    }
21
+}

+ 15
- 0
exercises/kindergarten-garden/src/main/java/KindergartenGarden.java 파일 보기

1
+import java.util.List;
2
+
3
+public class KindergartenGarden {
4
+    public KindergartenGarden(String garden, String[] students) {
5
+        throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
6
+    }
7
+
8
+    public KindergartenGarden(String garden) {
9
+        throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
10
+    }
11
+
12
+    public List<Plant> getPlantsOfStudent(String student) {
13
+        throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
14
+    }
15
+}

+ 21
- 0
exercises/kindergarten-garden/src/main/java/Plant.java 파일 보기

1
+public enum Plant {
2
+    VIOLETS,
3
+    RADISHES,
4
+    CLOVER,
5
+    GRASS;
6
+
7
+    public static Plant getPlant(char plantCode) {
8
+        switch (plantCode) {
9
+            case 'G':
10
+                return GRASS;
11
+            case 'C':
12
+                return CLOVER;
13
+            case 'R':
14
+                return RADISHES;
15
+            case 'V':
16
+                return VIOLETS;
17
+        }
18
+
19
+        return null;
20
+    }
21
+}

+ 182
- 0
exercises/kindergarten-garden/src/test/java/KindergartenGardenTest.java 파일 보기

1
+import java.util.List;
2
+import java.util.Arrays;
3
+
4
+import org.junit.Test;
5
+import org.junit.Ignore;
6
+
7
+import static org.junit.Assert.assertEquals;
8
+
9
+public class KindergartenGardenTest {
10
+
11
+    @Test
12
+    public void singleStudent() {
13
+        String student = "Alice";
14
+        String plants = "RC\nGG";
15
+        List<Plant> expected = Arrays.asList(Plant.RADISHES, Plant.CLOVER, Plant.GRASS, Plant.GRASS);
16
+
17
+        assertEquals(
18
+            expected,
19
+            new KindergartenGarden(plants).getPlantsOfStudent(student)
20
+        );
21
+    }
22
+
23
+    @Ignore("Remove to run test")
24
+    @Test
25
+    public void singleStudent2() {
26
+        String student = "Alice";
27
+        String plants = "VC\nRC";
28
+        List<Plant> expected = Arrays.asList(Plant.VIOLETS, Plant.CLOVER, Plant.RADISHES, Plant.CLOVER);
29
+
30
+        assertEquals(
31
+            expected,
32
+            new KindergartenGarden(plants).getPlantsOfStudent(student)
33
+        );
34
+    }
35
+
36
+    @Ignore("Remove to run test")
37
+    @Test
38
+    public void twoStudents() {
39
+        String student = "Bob";
40
+        String plants = "VVCG\nVVRC";
41
+        List<Plant> expected = Arrays.asList(Plant.CLOVER, Plant.GRASS, Plant.RADISHES, Plant.CLOVER);
42
+
43
+        assertEquals(
44
+            expected,
45
+            new KindergartenGarden(plants).getPlantsOfStudent(student)
46
+        );
47
+    }
48
+
49
+    @Ignore("Remove to run test")
50
+    @Test
51
+    public void oneGardenSecondStudent() {
52
+        String student = "Bob";
53
+        String plants = "VVCCGG\nVVCCGG";
54
+        List<Plant> expected = Arrays.asList(Plant.CLOVER, Plant.CLOVER, Plant.CLOVER, Plant.CLOVER);
55
+
56
+        assertEquals(
57
+            expected,
58
+            new KindergartenGarden(plants).getPlantsOfStudent(student)
59
+        );
60
+    }
61
+
62
+    @Ignore("Remove to run test")
63
+    @Test
64
+    public void oneGardenThirdStudent() {
65
+        String student = "Charlie";
66
+        String plants = "VVCCGG\nVVCCGG";
67
+        List<Plant> expected = Arrays.asList(Plant.GRASS, Plant.GRASS, Plant.GRASS, Plant.GRASS);
68
+
69
+        assertEquals(
70
+            expected,
71
+            new KindergartenGarden(plants).getPlantsOfStudent(student)
72
+        );
73
+    }
74
+
75
+    @Ignore("Remove to run test")
76
+    @Test
77
+    public void fullGardenFirstStudent() {
78
+        String student = "Alice";
79
+        String plants = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
80
+        List<Plant> expected = Arrays.asList(Plant.VIOLETS, Plant.RADISHES, Plant.VIOLETS, Plant.RADISHES);
81
+
82
+        assertEquals(
83
+            expected,
84
+            new KindergartenGarden(plants).getPlantsOfStudent(student)
85
+        );
86
+    }
87
+
88
+    @Ignore("Remove to run test")
89
+    @Test
90
+    public void fullGardenSecondStudent() {
91
+        String student = "Bob";
92
+        String plants = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
93
+        List<Plant> expected = Arrays.asList(Plant.CLOVER, Plant.GRASS, Plant.CLOVER, Plant.CLOVER);
94
+
95
+        assertEquals(
96
+            expected,
97
+            new KindergartenGarden(plants).getPlantsOfStudent(student)
98
+        );
99
+    }
100
+
101
+    @Ignore("Remove to run test")
102
+    @Test
103
+    public void fullGardenSecondToLastStudent() {
104
+        String student = "Kincaid";
105
+        String plants = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
106
+        List<Plant> expected = Arrays.asList(Plant.GRASS, Plant.CLOVER, Plant.CLOVER, Plant.GRASS);
107
+
108
+        assertEquals(
109
+            expected,
110
+            new KindergartenGarden(plants).getPlantsOfStudent(student)
111
+        );
112
+    }
113
+
114
+    @Ignore("Remove to run test")
115
+    @Test
116
+    public void fullGardenLastStudent() {
117
+        String student = "Larry";
118
+        String plants = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
119
+        List<Plant> expected = Arrays.asList(Plant.GRASS, Plant.VIOLETS, Plant.CLOVER, Plant.VIOLETS);
120
+
121
+        assertEquals(
122
+            expected,
123
+            new KindergartenGarden(plants).getPlantsOfStudent(student)
124
+        );
125
+    }
126
+
127
+    @Ignore("Remove to run test")
128
+    @Test
129
+    public void customStudentGardenFirstStudent() {
130
+        String[] studentArray = {"Samantha", "Patricia", "Xander", "Roger"};
131
+        String student = "Patricia";
132
+        String plants = "VCRRGVRG\nRVGCCGCV";
133
+        List<Plant> expected = Arrays.asList(Plant.VIOLETS, Plant.CLOVER, Plant.RADISHES, Plant.VIOLETS);
134
+
135
+        assertEquals(
136
+            expected,
137
+            new KindergartenGarden(plants, studentArray).getPlantsOfStudent(student)
138
+        );
139
+    }
140
+
141
+    @Ignore("Remove to run test")
142
+    @Test
143
+    public void customStudentGardenSecondStudent() {
144
+        String[] studentArray = {"Samantha", "Patricia", "Xander", "Roger"};
145
+        String student = "Roger";
146
+        String plants = "VCRRGVRG\nRVGCCGCV";
147
+        List<Plant> expected = Arrays.asList(Plant.RADISHES, Plant.RADISHES, Plant.GRASS, Plant.CLOVER);
148
+
149
+        assertEquals(
150
+            expected,
151
+            new KindergartenGarden(plants, studentArray).getPlantsOfStudent(student)
152
+        );
153
+    }
154
+
155
+    @Ignore("Remove to run test")
156
+    @Test
157
+    public void customStudentGardenThirdStudent() {
158
+        String[] studentArray = {"Samantha", "Patricia", "Xander", "Roger"};
159
+        String student = "Samantha";
160
+        String plants = "VCRRGVRG\nRVGCCGCV";
161
+        List<Plant> expected = Arrays.asList(Plant.GRASS, Plant.VIOLETS, Plant.CLOVER, Plant.GRASS);
162
+
163
+        assertEquals(
164
+            expected,
165
+            new KindergartenGarden(plants, studentArray).getPlantsOfStudent(student)
166
+        );
167
+    }
168
+
169
+    @Ignore("Remove to run test")
170
+    @Test
171
+    public void customStudentGardenFourthStudent() {
172
+        String[] studentArray = {"Samantha", "Patricia", "Xander", "Roger"};
173
+        String student = "Xander";
174
+        String plants = "VCRRGVRG\nRVGCCGCV";
175
+        List<Plant> expected = Arrays.asList(Plant.RADISHES, Plant.GRASS, Plant.CLOVER, Plant.VIOLETS);
176
+
177
+        assertEquals(
178
+            expected,
179
+            new KindergartenGarden(plants, studentArray).getPlantsOfStudent(student)
180
+        );
181
+    }
182
+}