Smarticles101 пре 9 година
родитељ
комит
dfade4d307

+ 50
- 50
exercises/kindergarten-garden/src/example/java/KindergartenGarden.java Прегледај датотеку

@@ -1,54 +1,54 @@
1 1
 import java.util.Arrays;
2 2
 
3 3
 public class KindergartenGarden {
4
-	private String[] students;
5
-	private String garden;
6
-	final int PARTITION_SIZE_WIDTH = 2;
7
-	final static String[] DEFAULT_STUDENTS = {
8
-			"Alice", "Bob", "Charlie", "David",
9
-        		"Eve", "Fred", "Ginny", "Harriet",
10
-        		"Ileana", "Joseph", "Kincaid", "Larry"
11
-		};
12
-
13
-	public KindergartenGarden(String garden, String[] students) {
14
-		this.garden = garden;
15
-		Arrays.sort(students);
16
-		this.students = students;
17
-	}
18
-
19
-	public KindergartenGarden(String garden) {
20
-		this(garden, DEFAULT_STUDENTS);
21
-	}
22
-
23
-	public String[] getPlantsOfStudent(String student) {
24
-		String[] plants = new String[PARTITION_SIZE_WIDTH * 2];
25
-		int studentPlantsIndex  = Arrays.binarySearch(students, student) * PARTITION_SIZE_WIDTH;
26
-		
27
-		for(int i = 0; i<PARTITION_SIZE_WIDTH; i++) {
28
-			plants[i] = getPlantName(garden.charAt(studentPlantsIndex + i));
29
-		}
30
-		
31
-		int newRowLocation = garden.indexOf('\n');
32
-		
33
-		for(int i = PARTITION_SIZE_WIDTH; i < PARTITION_SIZE_WIDTH * 2; i++) {
34
-			plants[i] = getPlantName(garden.charAt(newRowLocation - 1 + studentPlantsIndex + i));
35
-		}
36
-		
37
-		return plants;
38
-	}
39
-
40
-	public String getPlantName(char plantCode) {
41
-		switch(plantCode) {
42
-			case 'G':
43
-				return "grass";
44
-			case 'C':
45
-				return "clover";
46
-			case 'R':
47
-				return "radishes";
48
-			case 'V':
49
-				return "violets";
50
-		}
51
-		
52
-		return null;
53
-	}
4
+    private String[] students;
5
+    private String garden;
6
+    final int PARTITION_SIZE_WIDTH = 2;
7
+    final static String[] DEFAULT_STUDENTS = {
8
+            "Alice", "Bob", "Charlie", "David",
9
+            "Eve", "Fred", "Ginny", "Harriet",
10
+            "Ileana", "Joseph", "Kincaid", "Larry"
11
+    };
12
+
13
+    public KindergartenGarden(String garden, String[] students) {
14
+        this.garden = garden;
15
+        Arrays.sort(students);
16
+        this.students = students;
17
+    }
18
+
19
+    public KindergartenGarden(String garden) {
20
+        this(garden, DEFAULT_STUDENTS);
21
+    }
22
+
23
+    public String[] getPlantsOfStudent(String student) {
24
+        String[] plants = new String[PARTITION_SIZE_WIDTH * 2];
25
+        int studentPlantsIndex = Arrays.binarySearch(students, student) * PARTITION_SIZE_WIDTH;
26
+
27
+        for (int i = 0; i < PARTITION_SIZE_WIDTH; i++) {
28
+            plants[i] = getPlantName(garden.charAt(studentPlantsIndex + i));
29
+        }
30
+
31
+        int newRowLocation = garden.indexOf('\n');
32
+
33
+        for (int i = PARTITION_SIZE_WIDTH; i < PARTITION_SIZE_WIDTH * 2; i++) {
34
+            plants[i] = getPlantName(garden.charAt(newRowLocation - 1 + studentPlantsIndex + i));
35
+        }
36
+
37
+        return plants;
38
+    }
39
+
40
+    public String getPlantName(char plantCode) {
41
+        switch (plantCode) {
42
+            case 'G':
43
+                return "grass";
44
+            case 'C':
45
+                return "clover";
46
+            case 'R':
47
+                return "radishes";
48
+            case 'V':
49
+                return "violets";
50
+        }
51
+
52
+        return null;
53
+    }
54 54
 }

+ 2
- 2
exercises/kindergarten-garden/src/main/java/KindergartenGarden.java Прегледај датотеку

@@ -2,11 +2,11 @@ public class KindergartenGarden {
2 2
     public KindergartenGarden(String garden) {
3 3
         throw new UnsupportedOperationException("Method has not been implemented yet.");
4 4
     }
5
-    
5
+
6 6
     public KindergartenGarden(String garden, String[] students) {
7 7
         throw new UnsupportedOperationException("Method has not been implemented yet.");
8 8
     }
9
-    
9
+
10 10
     public String[] getStudentPlants(String student) {
11 11
         throw new UnsupportedOperationException("Method has not been implemented yet.");
12 12
     }

+ 94
- 94
exercises/kindergarten-garden/src/test/java/KindergartenGardenTest.java Прегледај датотеку

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