Pārlūkot izejas kodu

convert to bluej

Nhu Nguyen 6 gadus atpakaļ
vecāks
revīzija
e1b8167c86

+ 36
- 0
DuplicateDeleter.java Parādīt failu

@@ -0,0 +1,36 @@
1
+ 
2
+
3
+/**
4
+ * Created by leon on 1/25/18.
5
+ */
6
+public abstract class DuplicateDeleter<T> {
7
+    protected T[] array;
8
+
9
+    public DuplicateDeleter(T[] array) {
10
+        this.array = array;
11
+    }
12
+
13
+    /**
14
+     *  Removes all values in the array which occur n or more times
15
+     *
16
+     *  DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter();
17
+     *  Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
18
+     *  deleter.removeDuplicateExactly(array, 2); // => {56, 57, 58}
19
+     *
20
+     * @param maxNumberOfDuplications
21
+     * @return
22
+     */
23
+    abstract public T[] removeDuplicates(int maxNumberOfDuplications);
24
+
25
+    /**
26
+     *  Removes all the values in the array which occurs exactly n times
27
+     *
28
+     *  DuplicateDeleter<Integer> = new IntegerDuplicateDeleter();
29
+     *  Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
30
+     *  deleter.removeDuplicateExactly(array, 2); // => {1, 1, 1, 56, 57, 58}
31
+     *
32
+     * @param exactNumberOfDuplications
33
+     * @return
34
+     */
35
+    abstract public T[] removeDuplicatesExactly(int exactNumberOfDuplications);
36
+}

+ 6
- 0
IntegerDuplicateDeleter.java Parādīt failu

@@ -0,0 +1,6 @@
1
+ 
2
+
3
+
4
+public class IntegerDuplicateDeleter extends DuplicateDeleter<Integer>{
5
+
6
+}

+ 189
- 0
IntegerDuplicateDeleterTest.java Parādīt failu

@@ -0,0 +1,189 @@
1
+ 
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+import java.util.Arrays;
8
+
9
+/**
10
+ * Created by leon on 1/25/18.
11
+ * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
12
+ */
13
+public class IntegerDuplicateDeleterTest {
14
+
15
+    @Test
16
+    public void testRemoveDuplicatesExactly_whenThereIsOnlyOneElement() {
17
+        Integer[] intArray = new Integer[]{0};
18
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
19
+
20
+        Integer[] expected = new Integer[]{0};
21
+        Integer[] actual = deleter.removeDuplicatesExactly(2);
22
+        Assert.assertArrayEquals(expected, actual);
23
+    }
24
+
25
+    @Test
26
+    public void testRemoveDuplicatesExactly_whenThereIsOnlyOneElementAndRemoveDumplicationIs1() {
27
+        Integer[] intArray = new Integer[]{9};
28
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
29
+
30
+        Integer[] expected = new Integer[]{};
31
+        Integer[] actual = deleter.removeDuplicatesExactly(1);
32
+        Assert.assertArrayEquals(expected, actual);
33
+    }
34
+
35
+    @Test
36
+    public void testRemoveDuplicatesExactly_withNoElementsWithExactDumplication() {
37
+        Integer[] intArray = new Integer[]{51, 4, 4, 4, 28, 38, 38, 38, 38, 38};
38
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
39
+
40
+        Integer[] expected = new Integer[]{51, 4, 4, 4, 28, 38, 38, 38, 38, 38};
41
+        Integer[] actual = deleter.removeDuplicatesExactly(2);
42
+        Assert.assertArrayEquals(expected, actual);
43
+    }
44
+
45
+    @Test
46
+    public void testRemoveDuplicatesExactly_withMoreThanOneElement() {
47
+        Integer[] intArray = new Integer[]{5, 5, 1, 2, 2, 3, 3, 3};
48
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
49
+
50
+        Integer[] expected = new Integer[]{1, 3, 3, 3};
51
+        Integer[] actual = deleter.removeDuplicatesExactly(2);
52
+        Assert.assertArrayEquals(expected, actual);
53
+    }
54
+
55
+    @Test
56
+    public void testRemoveDuplicatesExactly_withOccuranceAtTheBeginningAndEnd() {
57
+        Integer[] intArray = new Integer[]{0, 0, 0, 1, 2, 2, 4, 4, 5, 5, 5, 6, 9, 9, 9};
58
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
59
+
60
+        Integer[] expected = new Integer[]{1, 2, 2, 4, 4, 6};
61
+        Integer[] actual = deleter.removeDuplicatesExactly(3);
62
+        Assert.assertArrayEquals(expected, actual);
63
+    }
64
+
65
+
66
+    @Test
67
+    public void testRemoveDuplicatesExactly_withOccuranceInTheMiddle() {
68
+        Integer[] intArray = new Integer[]{0, 0, 0, 1, 2, 2, 4, 4, 5, 5, 5, 6, 9, 9, 9};
69
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
70
+
71
+        Integer[] expected = new Integer[]{0, 0, 0, 1, 5, 5, 5, 6, 9, 9, 9};
72
+        Integer[] actual = deleter.removeDuplicatesExactly(2);
73
+        Assert.assertArrayEquals(expected, actual);
74
+    }
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+    @Test
86
+    public void testRemoveDuplicates_whenThereIsOnlyOneElement() {
87
+        Integer[] intArray = new Integer[]{5};
88
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
89
+
90
+        Integer[] expected = new Integer[]{5};
91
+        Integer[] actual = deleter.removeDuplicates(2);
92
+        Assert.assertArrayEquals(expected, actual);
93
+    }
94
+
95
+    @Test
96
+    public void testRemoveDuplicates_whenThereIsOnlyOneElementAndRemoveDumplicationIs1() {
97
+        Integer[] intArray = new Integer[]{3};
98
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
99
+
100
+        Integer[] expected = new Integer[]{};
101
+        Integer[] actual = deleter.removeDuplicatesExactly(1);
102
+        Assert.assertArrayEquals(expected, actual);
103
+    }
104
+
105
+    @Test
106
+    public void testRemoveDuplicates_whenThereIsMoreThanOneElement() {
107
+        Integer[] intArray = new Integer[]{4, 1, 2};
108
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
109
+
110
+        Integer[] expected = new Integer[]{4, 1, 2};
111
+        Integer[] actual = deleter.removeDuplicates(2);
112
+        Assert.assertArrayEquals(expected, actual);
113
+    }
114
+
115
+    @Test
116
+    public void testRemoveDuplicates_whenThereIsMoreThanOneElementWithOccurance() {
117
+        Integer[] intArray = new Integer[]{4, 4, 1, 2, 2, 2};
118
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
119
+
120
+        Integer[] expected = new Integer[]{1};
121
+        Integer[] actual = deleter.removeDuplicates(2);
122
+        Assert.assertArrayEquals(expected, actual);
123
+    }
124
+
125
+    @Test
126
+    public void testRemoveDuplicates_removesNothing() {
127
+        Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
128
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
129
+        Integer[] expected = new Integer[]{};
130
+        Integer[] actual = deleter.removeDuplicates(0);
131
+        Assert.assertArrayEquals(expected, actual);
132
+    }
133
+
134
+    @Test
135
+    public void testRemoveDuplicates_withOccuranceInTheMiddle() {
136
+        Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
137
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
138
+        Integer[] expected = new Integer[]{2};
139
+        Integer[] actual = deleter.removeDuplicates(2);
140
+        Assert.assertArrayEquals(expected, actual);
141
+    }
142
+
143
+
144
+    @Test
145
+    public void testRemoveDuplicates_withOccuranceAtTheBeginningAndEnd() {
146
+        Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
147
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
148
+        Integer[] expected = new Integer[]{1, 1, 2, 4, 4};
149
+        Integer[] actual = deleter.removeDuplicates(3);
150
+        Assert.assertArrayEquals(expected, actual);
151
+    }
152
+
153
+
154
+
155
+
156
+
157
+    @Test
158
+    public void testRemoveDuplicatesExactlyIdempotence() {
159
+        Integer[] input = {11, 3, 3, 3, 4, 4, 4, 4};
160
+        Integer[] expected = {11, 4, 4, 4, 4};
161
+
162
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(input);
163
+
164
+        Integer[] actual1 = deleter.removeDuplicatesExactly(3);
165
+        Integer[] actual2 = deleter.removeDuplicatesExactly(3);
166
+        Integer[] actual3 = deleter.removeDuplicatesExactly(3);
167
+
168
+        Assert.assertArrayEquals(expected, actual1);
169
+        Assert.assertArrayEquals(expected, actual2);
170
+        Assert.assertArrayEquals(expected, actual3);
171
+    }
172
+
173
+
174
+    @Test
175
+    public void testRemoveDuplicatesIdempotence() {
176
+        Integer[] input = {1, 2, 2, 2, 3, 4, 4};
177
+        Integer[] expected = {1, 3};
178
+
179
+        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(input);
180
+
181
+        Integer[] actual1 = deleter.removeDuplicates(2);
182
+        Integer[] actual2 = deleter.removeDuplicates(2);
183
+        Integer[] actual3 = deleter.removeDuplicates(2);
184
+
185
+        Assert.assertArrayEquals(expected, actual1);
186
+        Assert.assertArrayEquals(expected, actual2);
187
+        Assert.assertArrayEquals(expected, actual3);
188
+    }
189
+}

+ 39
- 114
README.md Parādīt failu

@@ -1,5 +1,5 @@
1 1
 
2
-# Delete Duplicates 
2
+# Delete Duplicates
3 3
 * **Objective**
4 4
 	* To write methods which remove duplicate elements from an array.
5 5
 * **Purpose**
@@ -42,48 +42,36 @@
42 42
 
43 43
     ```
44 44
     // : Given
45
-    Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
45
+    Integer[] array = new Integer[]{1, 1, 1, 23, 23, 56, 57, 58};
46 46
     DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
47
-    
47
+
48 48
     // : When
49 49
     Integer[] actual = deleter.removeDuplicateExactly(3);
50
-    
50
+
51 51
     // : Then
52
-    System.out.println(Arrays.toString(actual));
52
+		Integer[] expected = new Integer[]{23, 23, 56, 57, 58};
53
+    assertArrayEquals(expected, actual);
53 54
     ```
54 55
 
55
-* Sample Output
56 56
 
57
-    ```
58
-    [23,23,56,57,58]
59
-    ```
60
-    
61
-    
62
-    
63 57
 
64 58
 ### Example 2
65 59
 * Sample Script
66 60
 
67 61
     ```
68 62
     // : Given
69
-    Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
63
+    Integer[] array = new Integer[]{1, 1, 1, 23, 23, 56, 57, 58};
70 64
     DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
71
-    
65
+
72 66
     // : When
73 67
     Integer[] actual = deleter.removeDuplicateExactly(1);
74
-    
68
+
75 69
     // : Then
76
-    System.out.println(Arrays.toString(actual));
70
+		Integer[] expected = {1, 1, 1, 23, 23};
71
+    assertArrayEquals(expected, actual);
77 72
     ```
78 73
 
79
-* Sample Output
80 74
 
81
-    ```
82
-    [1,1,1,23,23]
83
-    ```
84
-    
85
-    
86
-    
87 75
 
88 76
 ### Example 3
89 77
 * Sample Script
@@ -92,38 +80,17 @@
92 80
     // : Given
93 81
     Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
94 82
     DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
95
-    
83
+
96 84
     // : When
97 85
     Integer[] actual = deleter.removeDuplicateExactly(3);
98
-    
99
-    // : Then
100
-    System.out.println(Arrays.toString(actual));
101
-    ```
102 86
 
103
-* Sample Output
104
-
105
-    ```
106
-    [1, 1, 2, 4, 4, 5, 5, 5, 5]
87
+    // : Then
88
+		Integer[] expected = {1, 1, 2, 4, 4, 5, 5, 5, 5};
89
+    assertArrayEquals(expected, actual);
107 90
     ```
108 91
 
109 92
 
110 93
 
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127 94
 <br><br><br><br>
128 95
 ## `removeDuplicates(n)`
129 96
 
@@ -134,25 +101,16 @@
134 101
     // : Given
135 102
     Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
136 103
     DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
137
-    
104
+
138 105
     // : When
139 106
     Integer[] actual = deleter.removeDuplicateExactly(1);
140
-    
141
-    // : Then
142
-    System.out.println(Arrays.toString(actual));
143
-    ```
144
-
145
-
146 107
 
147
-* Sample Output
148
-
149
-    ```
150
-    []
108
+    // : Then
109
+		Integer[] expected = {};
110
+    assertArrayEquals(expected, actual);
151 111
     ```
152 112
 
153 113
 
154
-
155
-
156 114
 ### Example 2
157 115
 * Sample Script
158 116
 
@@ -160,24 +118,16 @@
160 118
     // : Given
161 119
     Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
162 120
     DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
163
-    
121
+
164 122
     // : When
165 123
     Integer[] actual = deleter.removeDuplicates(2);
166
-    
167
-    // : Then
168
-    System.out.println(Arrays.toString(actual));
169
-    ```
170
-
171
-
172 124
 
173
-* Sample Output
174
-
175
-    ```
176
-    [2]
125
+    // : Then
126
+		Integer[] expected = {2};
127
+    assertArrayEquals(expected, actual);
177 128
     ```
178 129
 
179 130
 
180
-
181 131
 ### Example 3
182 132
 * Sample Script
183 133
 
@@ -185,31 +135,19 @@
185 135
     // : Given
186 136
     Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
187 137
     DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
188
-    
138
+
189 139
     // : When
190 140
     Integer[] actual = deleter.removeDuplicates(3);
191
-    
141
+
192 142
     // : Then
193
-    System.out.println(Arrays.toString(actual));
143
+		Integer[] expected = {1, 1, 2, 4, 4};
144
+    assertArrayEquals(expected, actual);
194 145
     ```
195 146
 
196 147
 
197 148
 
198
-* Sample Output
199 149
 
200
-    ```
201
-    [1,1,2,4,4]
202
-    ```
203
-    
204
-    
205
-    
206
-    
207
-    
208
-    
209
-    
210
-    
211
-    
212
-    
150
+
213 151
 <br><br><br><br>
214 152
 ## Idempotence
215 153
 
@@ -223,45 +161,32 @@
223 161
     deleter.removeDuplicates(0);
224 162
     deleter.removeDuplicates(1);
225 163
     deleter.removeDuplicates(2);
226
-    
164
+
227 165
     // : When
228 166
     Integer[] actual = deleter.removeDuplicates(3);
229
-    
167
+
230 168
     // : Then
231
-    System.out.println(Arrays.toString(actual));
169
+		Integer[] expected = {1, 1, 2, 4, 4};
170
+    assertArrayEquals(expected, actual);
232 171
     ```
233 172
 
234 173
 
235
-
236
-* Sample Output
237
-
238
-    ```
239
-    [1,1,2,4,4]
240
-    ```
241
-    
242
-
243 174
 ### Example 2
244 175
 * Sample Script
245 176
 
246 177
     ```
247 178
     // : Given
248
-    Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
179
+    Integer[] array = new Integer[]{1, 1, 1, 23, 23, 56, 57, 58};
249 180
     DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
250
-    deleter.removeDuplicates(0);
181
+
182
+		deleter.removeDuplicates(0);
251 183
     deleter.removeDuplicates(1);
252 184
     deleter.removeDuplicates(2);
253
-    
185
+
254 186
     // : When
255 187
     Integer[] actual = deleter.removeDuplicatesExactly(3);
256
-    
257
-    // : Then
258
-    System.out.println(Arrays.toString(actual));
259
-    ```
260
-
261 188
 
262
-
263
-* Sample Output
264
-
265
-    ```
266
-    [23,23,56,57,58]
189
+    // : Then
190
+		Integer[] expected = {23, 23, 56, 57, 58};
191
+    assertArrayEquals(expected, actual);
267 192
     ```

+ 6
- 0
StringDuplicateDeleter.java Parādīt failu

@@ -0,0 +1,6 @@
1
+ 
2
+
3
+public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
4
+
5
+
6
+}

+ 180
- 0
StringDuplicateDeleterTest.java Parādīt failu

@@ -0,0 +1,180 @@
1
+ 
2
+
3
+
4
+import org.junit.Assert;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+import java.util.Arrays;
9
+
10
+/**
11
+ * Created by leon on 1/28/18.
12
+ * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
13
+ */
14
+public class StringDuplicateDeleterTest {
15
+    @Test
16
+    public void testRemoveDuplicatesExactly_whenThereIsOnlyOneElement() {
17
+        String[] array = new String[]{"a"};
18
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
19
+
20
+        String[] expected = new String[]{"a"};
21
+        String[] actual = deleter.removeDuplicatesExactly(2);
22
+        Assert.assertArrayEquals(expected, actual);
23
+    }
24
+
25
+    @Test
26
+    public void testRemoveDuplicatesExactly_whenThereIsOnlyOneElementAndRemoveDumplicationIs1() {
27
+        String[] array = new String[]{"b"};
28
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
29
+
30
+        String[] expected = new String[]{};
31
+        String[] actual = deleter.removeDuplicatesExactly(1);
32
+        Assert.assertArrayEquals(expected, actual);
33
+    }
34
+
35
+    @Test
36
+    public void testRemoveDuplicatesExactly_withNoElementsToRemove() {
37
+        String[] array = new String[]{"aa", "b", "d"};
38
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
39
+
40
+        String[] expected = new String[]{"aa", "b", "d"};
41
+        String[] actual = deleter.removeDuplicatesExactly(2);
42
+        Assert.assertArrayEquals(expected, actual);
43
+    }
44
+
45
+    @Test
46
+    public void testRemoveDuplicatesExactly_withMoreThanOneElementToRemove() {
47
+        String[] array = new String[]{"cat", "cat", "dog", "dog", "fox"};
48
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
49
+
50
+        String[] expected = new String[]{"fox"};
51
+        String[] actual = deleter.removeDuplicatesExactly(2);
52
+        Assert.assertArrayEquals(expected, actual);
53
+    }
54
+
55
+    @Test
56
+    public void testRemoveDuplicatesExactly_withOccuranceAtTheBeginningAndEnd() {
57
+        String[] array = new String[]{"cat", "cat", "cat", "deer", "deer", "dog", "fox", "fox", "goat", "goat", "goat"};
58
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
59
+
60
+        String[] expected = new String[]{"deer", "deer", "dog", "fox", "fox"};
61
+        String[] actual = deleter.removeDuplicatesExactly(3);
62
+        Assert.assertArrayEquals(expected, actual);
63
+    }
64
+
65
+
66
+    @Test
67
+    public void testRemoveDuplicatesExactly_withOccuranceInTheMiddle() {
68
+        String[] array = new String[]{"cat", "cat", "cat", "deer", "deer", "dog", "fox", "fox", "goat", "goat", "goat"};
69
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
70
+
71
+        String[] expected = new String[]{"cat", "cat", "cat", "dog", "goat", "goat", "goat"};
72
+        String[] actual = deleter.removeDuplicatesExactly(2);
73
+        Assert.assertArrayEquals(expected, actual);
74
+    }
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+    @Test
86
+    public void testRemoveDuplicates_withOneElement() {
87
+        String[] array = new String[]{"Droolius Caesar"};
88
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
89
+
90
+        String[] expected = new String[]{"Droolius Caesar"};
91
+        String[] actual = deleter.removeDuplicates(2);
92
+        Assert.assertArrayEquals(expected, actual);
93
+    }
94
+
95
+    @Test
96
+    public void testRemoveDuplicates_withOneElementToRemove() {
97
+        String[] array = new String[]{"Chewbarka"};
98
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
99
+
100
+        String[] expected = new String[]{};
101
+        String[] actual = deleter.removeDuplicatesExactly(1);
102
+        Assert.assertArrayEquals(expected, actual);
103
+    }
104
+
105
+    @Test
106
+    public void testRemoveDuplicates_withNoElementToRemove() {
107
+        String[] array = new String[]{"a", "a", "b", "c", "c", "c", "d"};
108
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
109
+
110
+        String[] expected = new String[]{"a", "a", "b", "c", "c", "c", "d"};
111
+        String[] actual = deleter.removeDuplicates(4);
112
+        Assert.assertArrayEquals(expected, actual);
113
+    }
114
+
115
+    @Test
116
+    public void testRemoveDuplicates_whenThereIsMoreThanOneElementWithOccurance() {
117
+        String[] array = new String[]{"a", "a", "b", "c", "c", "c", "d"};
118
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
119
+
120
+        String[] expected = new String[]{"b", "d"};
121
+        String[] actual = deleter.removeDuplicates(2);
122
+        Assert.assertArrayEquals(expected, actual);
123
+    }
124
+
125
+    @Test
126
+    public void testRemoveDuplicates_withOccuranceInTheMiddle() {
127
+        String[] array = new String[]{"aba", "baa", "baa", "bbb", "bbb", "bbb", "cat", "cat", "dog"};
128
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
129
+        String[] expected = new String[]{"aba", "dog"};
130
+        String[] actual = deleter.removeDuplicates(2);
131
+        Assert.assertArrayEquals(expected, actual);
132
+    }
133
+
134
+
135
+    @Test
136
+    public void testRemoveDuplicates_withOccuranceAtTheBeginningAndEnd() {
137
+        String[] array = new String[]{"aba", "aba", "aba", "bab", "aaa", "bba", "bba", "bbb", "bbb", "bbb"};
138
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(array);
139
+        String[] expected = new String[]{"bab", "aaa", "bba", "bba"};
140
+        String[] actual = deleter.removeDuplicates(3);
141
+        Assert.assertArrayEquals(expected, actual);
142
+    }
143
+
144
+
145
+
146
+
147
+
148
+    @Test
149
+    public void testRemoveDuplicatesExactlyIdempotence() {
150
+        String[] input = {"aa", "b", "b", "b", "c", "c", "t", "t", "t"};
151
+        String[] expected = {"aa", "c", "c"};
152
+
153
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(input);
154
+
155
+        String[] actual1 = deleter.removeDuplicatesExactly(3);
156
+        String[] actual2 = deleter.removeDuplicatesExactly(3);
157
+        String[] actual3 = deleter.removeDuplicatesExactly(3);
158
+
159
+        Assert.assertArrayEquals(expected, actual1);
160
+        Assert.assertArrayEquals(expected, actual2);
161
+        Assert.assertArrayEquals(expected, actual3);
162
+    }
163
+
164
+
165
+    @Test
166
+    public void testRemoveDuplicatesIdempotence() {
167
+        String[] input = {"aa", "b", "b", "b", "c", "c", "t", "t"};
168
+        String[] expected = {"aa"};
169
+
170
+        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(input);
171
+
172
+        String[] actual1 = deleter.removeDuplicates(2);
173
+        String[] actual2 = deleter.removeDuplicates(2);
174
+        String[] actual3 = deleter.removeDuplicates(2);
175
+
176
+        Assert.assertArrayEquals(expected, actual1);
177
+        Assert.assertArrayEquals(expected, actual2);
178
+        Assert.assertArrayEquals(expected, actual3);
179
+    }
180
+}

+ 101
- 0
package.bluej Parādīt failu

@@ -0,0 +1,101 @@
1
+#BlueJ package file
2
+dependency1.from=StringDuplicateDeleterTest
3
+dependency1.to=StringDuplicateDeleter
4
+dependency1.type=UsesDependency
5
+dependency2.from=StringDuplicateDeleterTest
6
+dependency2.to=TestUtils
7
+dependency2.type=UsesDependency
8
+dependency3.from=StringDuplicateDeleterTest
9
+dependency3.to=RandomNumberFactory
10
+dependency3.type=UsesDependency
11
+dependency4.from=IntegerDuplicateDeleterTest
12
+dependency4.to=IntegerDuplicateDeleter
13
+dependency4.type=UsesDependency
14
+dependency5.from=IntegerDuplicateDeleterTest
15
+dependency5.to=TestUtils
16
+dependency5.type=UsesDependency
17
+dependency6.from=IntegerDuplicateDeleterTest
18
+dependency6.to=RandomNumberFactory
19
+dependency6.type=UsesDependency
20
+editor.fx.0.height=722
21
+editor.fx.0.width=988
22
+editor.fx.0.x=425
23
+editor.fx.0.y=176
24
+objectbench.height=189
25
+objectbench.width=1211
26
+package.divider.horizontal=0.6
27
+package.divider.vertical=0.6979969183359014
28
+package.editor.height=446
29
+package.editor.width=1109
30
+package.editor.x=142
31
+package.editor.y=61
32
+package.frame.height=707
33
+package.frame.width=1235
34
+package.numDependencies=6
35
+package.numTargets=8
36
+package.showExtends=true
37
+package.showUses=true
38
+project.charset=UTF-8
39
+readme.height=58
40
+readme.name=@README
41
+readme.width=47
42
+readme.x=10
43
+readme.y=10
44
+target1.height=50
45
+target1.name=TestUtils
46
+target1.showInterface=false
47
+target1.type=ClassTarget
48
+target1.width=80
49
+target1.x=750
50
+target1.y=210
51
+target2.association=StringDuplicateDeleterTest
52
+target2.height=50
53
+target2.name=StringDuplicateDeleter
54
+target2.showInterface=false
55
+target2.type=ClassTarget
56
+target2.width=170
57
+target2.x=90
58
+target2.y=40
59
+target3.height=50
60
+target3.name=RandomNumberFactory
61
+target3.showInterface=false
62
+target3.type=ClassTarget
63
+target3.width=170
64
+target3.x=230
65
+target3.y=130
66
+target4.height=50
67
+target4.name=DuplicateDeleterInterface
68
+target4.showInterface=false
69
+target4.type=InterfaceTarget
70
+target4.width=210
71
+target4.x=480
72
+target4.y=30
73
+target5.association=IntegerDuplicateDeleterTest
74
+target5.height=50
75
+target5.name=IntegerDuplicateDeleter
76
+target5.showInterface=false
77
+target5.type=ClassTarget
78
+target5.width=170
79
+target5.x=40
80
+target5.y=220
81
+target6.height=50
82
+target6.name=StringDuplicateDeleterTest
83
+target6.showInterface=false
84
+target6.type=UnitTestTargetJunit4
85
+target6.width=170
86
+target6.x=120
87
+target6.y=10
88
+target7.height=50
89
+target7.name=IntegerDuplicateDeleterTest
90
+target7.showInterface=false
91
+target7.type=UnitTestTargetJunit4
92
+target7.width=170
93
+target7.x=70
94
+target7.y=190
95
+target8.height=50
96
+target8.name=DuplicateDeleter
97
+target8.showInterface=false
98
+target8.type=AbstractTarget
99
+target8.width=160
100
+target8.x=450
101
+target8.y=120

+ 0
- 15
src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleter.java Parādīt failu

@@ -1,15 +0,0 @@
1
-package com.zipcodewilmington.looplabs;
2
-
3
-/**
4
- * Created by leon on 1/25/18.
5
- */
6
-public abstract class DuplicateDeleter<T> implements DuplicateDeleterInterface<T> {
7
-    protected T[] array;
8
-
9
-    public DuplicateDeleter(T[] intArray) {
10
-        this.array = intArray;
11
-    }
12
-
13
-    abstract public T[] removeDuplicates(int maxNumberOfDuplications);
14
-    abstract public T[] removeDuplicatesExactly(int exactNumberOfDuplications);
15
-}

+ 0
- 10
src/main/java/com/zipcodewilmington/looplabs/DuplicateDeleterInterface.java Parādīt failu

@@ -1,10 +0,0 @@
1
-package com.zipcodewilmington.looplabs;
2
-
3
-/**
4
- * Created by leon on 1/28/18.
5
- * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
6
- */
7
-public interface DuplicateDeleterInterface<T> {
8
-    T[] removeDuplicates(int maxNumberOfDuplications);
9
-    T[] removeDuplicatesExactly(int exactNumberOfDuplications);
10
-}

+ 0
- 8
src/main/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleter.java Parādīt failu

@@ -1,8 +0,0 @@
1
-package com.zipcodewilmington.looplabs;
2
-
3
-/**
4
- * Created by leon on 1/29/18.
5
- * @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
6
- */
7
-public final class IntegerDuplicateDeleter extends DuplicateDeleter<Integer> {
8
-}

+ 0
- 80
src/main/java/com/zipcodewilmington/looplabs/RandomNumberFactory.java Parādīt failu

@@ -1,80 +0,0 @@
1
-package com.zipcodewilmington.looplabs;
2
-
3
-import java.util.Random;
4
-
5
-/**
6
- * @author leon.hunter
7
- * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
8
- */
9
-public final class RandomNumberFactory {
10
-    private static volatile Random random = new Random();
11
-
12
-    private RandomNumberFactory() {
13
-    }
14
-    /**
15
-     * @param min
16
-     * @param max
17
-     * @return a random character between the specified min and max character range
18
-     */
19
-    public static Character createCharacter(char min, char max) {
20
-        return (char) createInteger((int) min, (int) max).intValue();
21
-    }
22
-
23
-    /**
24
-     * @param min
25
-     * @param max
26
-     * @return a random float between the specified minimum and maximum numeric range
27
-     */
28
-    public static synchronized Float createFloat(float min, float max) {
29
-        return random.nextFloat() * (max - min) + min;
30
-    }
31
-
32
-    /**
33
-     * @param min
34
-     * @param max
35
-     * @return a random integer between the specified minimum and maximum numeric range
36
-     */
37
-    public static Integer createInteger(Integer min, Integer max) {
38
-        return createFloat(min, max).intValue();
39
-    }
40
-
41
-    /**
42
-     * @param min
43
-     * @param max
44
-     * @return an array the specified length containing integers in the specified range
45
-     */
46
-    public static Integer[] createIntegers(int min, int max, int length) {
47
-        Integer[] integers = new Integer[length];
48
-        for(int i=0; i<length; i++) {
49
-            integers[i] = createInteger(min, max);
50
-        }
51
-        return integers;
52
-    }
53
-
54
-    /**
55
-     * @param min
56
-     * @param max
57
-     * @return a random string of the specified length containing characters in the specified range
58
-     */
59
-    public static String createString(char min, char max, int length) {
60
-        StringBuilder sb = new StringBuilder();
61
-        for (int i = 0; i < length; i++) {
62
-            sb.append(createCharacter(min, max));
63
-        }
64
-        return sb.toString();
65
-    }
66
-
67
-
68
-    /**
69
-     * @param min
70
-     * @param max
71
-     * @return an array containing arrays of specified length containing characters in the specified range
72
-     */
73
-    public static String[] createStrings(char min, char max, int stringLength, int arrayLength) {
74
-        String[] array = new String[arrayLength];
75
-        for(int i=0; i<arrayLength; i++) {
76
-            array[i] = createString(min, max, stringLength);
77
-        }
78
-        return array;
79
-    }
80
-}

+ 0
- 8
src/main/java/com/zipcodewilmington/looplabs/StringDuplicateDeleter.java Parādīt failu

@@ -1,8 +0,0 @@
1
-package com.zipcodewilmington.looplabs;
2
-
3
-/**
4
- * Created by leon on 1/28/18.
5
- * @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
6
- */
7
-public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
8
-}

+ 0
- 183
src/test/java/com/zipcodewilmington/looplabs/IntegerDuplicateDeleterTest.java Parādīt failu

@@ -1,183 +0,0 @@
1
-package com.zipcodewilmington.looplabs;
2
-
3
-import org.junit.Before;
4
-import org.junit.Test;
5
-
6
-import java.util.Arrays;
7
-
8
-/**
9
- * Created by leon on 1/25/18.
10
- * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
11
- */
12
-public class IntegerDuplicateDeleterTest {
13
-
14
-    private static Integer[] intArray;
15
-    private static DuplicateDeleter<Integer> deleter;
16
-
17
-    @Before
18
-    public void setup() {
19
-        this.intArray = new Integer[]{0, 0, 0, 1, 2, 2, 4, 4, 5, 5, 5, 6, 9, 9, 9};
20
-        this.deleter = new IntegerDuplicateDeleter(intArray);
21
-    }
22
-
23
-
24
-    @Test
25
-    public void testRemoveDuplicatesExactlyExactly() {
26
-        Integer[] expected = new Integer[]{1, 2, 2, 4, 4, 6};
27
-        Integer[] actual = deleter.removeDuplicatesExactly(3);
28
-        TestUtils.assertArrayEquality(expected, actual);
29
-    }
30
-
31
-
32
-    @Test
33
-    public void testRemoveDuplicatesExactly1() {
34
-        Integer[] expected = new Integer[]{0, 0, 0, 1, 5, 5, 5, 6, 9, 9, 9};
35
-        Integer[] actual = deleter.removeDuplicatesExactly(2);
36
-        TestUtils.assertArrayEquality(expected, actual);
37
-    }
38
-
39
-
40
-
41
-    @Test
42
-    public void testRemoveDuplicatesExactly2() {
43
-        Integer[] expected = new Integer[]{0, 0, 0, 2, 2, 4, 4, 5, 5, 5, 9, 9, 9};
44
-        Integer[] actual = deleter.removeDuplicatesExactly(1);
45
-        TestUtils.assertArrayEquality(expected, actual);
46
-    }
47
-
48
-
49
-    @Test
50
-    public void testRemoveDuplicatesExactly3() {
51
-        Integer[] expected = new Integer[]{1, 2, 2, 4, 4, 6};
52
-        deleter.removeDuplicates(3);
53
-        deleter.removeDuplicatesExactly(2);
54
-        deleter.removeDuplicatesExactly(1);
55
-
56
-        Integer[] actual = deleter.removeDuplicatesExactly(3);
57
-        TestUtils.assertArrayEquality(expected, actual);
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
-    @Test
87
-    public void testRemoveDuplicates0() {
88
-        Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
89
-        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
90
-        Integer[] expected = new Integer[]{};
91
-        Integer[] actual = deleter.removeDuplicates(0);
92
-        TestUtils.assertArrayEquality(expected, actual);
93
-    }
94
-
95
-
96
-    @Test
97
-    public void testRemoveDuplicates1() {
98
-        Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
99
-        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
100
-        Integer[] expected = new Integer[]{};
101
-        Integer[] actual = deleter.removeDuplicates(1);
102
-        TestUtils.assertArrayEquality(expected, actual);
103
-    }
104
-
105
-
106
-    @Test
107
-    public void testRemoveDuplicates2() {
108
-        Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
109
-        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
110
-        Integer[] expected = new Integer[]{2};
111
-        Integer[] actual = deleter.removeDuplicates(2);
112
-        TestUtils.assertArrayEquality(expected, actual);
113
-    }
114
-
115
-
116
-    @Test
117
-    public void testRemoveDuplicates3() {
118
-        Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
119
-        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
120
-        Integer[] expected = new Integer[]{1,1,2,4,4};
121
-        Integer[] actual = deleter.removeDuplicates(3);
122
-        TestUtils.assertArrayEquality(expected, actual);
123
-    }
124
-
125
-
126
-    @Test
127
-    public void testRemoveDuplicates4() {
128
-        Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
129
-        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
130
-        Integer[] expected = new Integer[]{0,0,0,1,1,2,3,3,3,4,4};
131
-        Integer[] actual = deleter.removeDuplicates(4);
132
-        TestUtils.assertArrayEquality(expected, actual);
133
-    }
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-    @Test
150
-    public void testRemoveDuplicatesExactlyIdempotence() {
151
-        Integer[] input = RandomNumberFactory.createIntegers(0,50,150);
152
-        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(input);
153
-        Integer[] expected = deleter.removeDuplicatesExactly(5);
154
-
155
-        for (int i = 0; i < input.length; i++) {
156
-            deleter.removeDuplicatesExactly(i);
157
-        }
158
-
159
-        Integer[] actual = deleter.removeDuplicatesExactly(5);
160
-
161
-        Arrays.sort(input);
162
-        System.out.println("Input:\n\t" + Arrays.toString(input));
163
-        TestUtils.assertArrayEquality(expected, actual);
164
-    }
165
-
166
-
167
-    @Test
168
-    public void testRemoveDuplicatesIdempotence() {
169
-        Integer[] input = RandomNumberFactory.createIntegers(0,50,150);
170
-        DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(input);
171
-        Integer[] expected = deleter.removeDuplicates(5);
172
-
173
-        for (int i = 0; i < input.length; i++) {
174
-            deleter.removeDuplicates(i);
175
-        }
176
-
177
-        Integer[] actual = deleter.removeDuplicates(5);
178
-
179
-        Arrays.sort(input);
180
-        System.out.println("Input:\n\t" + Arrays.toString(input));
181
-        TestUtils.assertArrayEquality(expected, actual);
182
-    }
183
-}

+ 0
- 171
src/test/java/com/zipcodewilmington/looplabs/StringDuplicateDeleterTest.java Parādīt failu

@@ -1,171 +0,0 @@
1
-package com.zipcodewilmington.looplabs;
2
-
3
-
4
-import org.junit.Before;
5
-import org.junit.Test;
6
-
7
-import java.util.Arrays;
8
-
9
-/**
10
- * Created by leon on 1/28/18.
11
- * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
12
- */
13
-public class StringDuplicateDeleterTest {
14
-    private static String[] stringArray;
15
-    private static volatile DuplicateDeleter<String> deleter;
16
-
17
-    @Before
18
-    public void setup() {
19
-        this.stringArray = new String[]{"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
20
-        this.deleter = new StringDuplicateDeleter(stringArray);
21
-    }
22
-
23
-
24
-    @Test
25
-    public void testRemoveDuplicatesExactly1() {
26
-        String[] expected = new String[]{"aba", "aba", "bba", "bba", "bba", "bba", "bbb", "bbb"};
27
-        String[] actual = deleter.removeDuplicatesExactly(1);
28
-        TestUtils.assertArrayEquality(expected, actual);
29
-    }
30
-
31
-
32
-    @Test
33
-    public void testRemoveDuplicatesExactly2() {
34
-        String[] expected = new String[]{"baa", "bab", "bba", "bba", "bba", "bba"};
35
-        String[] actual = deleter.removeDuplicatesExactly(2);
36
-        TestUtils.assertArrayEquality(expected, actual);
37
-    }
38
-
39
-
40
-    @Test
41
-    public void testRemoveDuplicatesExactly3() {
42
-        String[] expected = new String[]{"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
43
-        String[] actual = deleter.removeDuplicatesExactly(3);
44
-        TestUtils.assertArrayEquality(expected, actual);
45
-    }
46
-
47
-
48
-    @Test
49
-    public void testRemoveDuplicatesExactly4() {
50
-        String[] expected = new String[]{"aba", "aba", "baa", "bab", "bbb", "bbb"};
51
-        String[] actual = deleter.removeDuplicatesExactly(4);
52
-        TestUtils.assertArrayEquality(expected, actual);
53
-    }
54
-
55
-
56
-    @Test
57
-    public void testRemoveDuplicatesExactly5() {
58
-        String[] input = new String[]{"aa", "aa", "aa", "aa", "aa", "ab", "ba", "ba", "ba", "ba", "bb", "bb", "bb", "bb", "bb"};
59
-        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(input);
60
-        String[] expected = new String[]{"ab", "ba", "ba", "ba", "ba"};
61
-        String[] actual = deleter.removeDuplicatesExactly(5);
62
-        TestUtils.assertArrayEquality(expected, actual);
63
-    }
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-    @Test
79
-    public void testRemoveDuplicates0() {
80
-        String[] input = new String[]{"aa", "aa", "aa", "aa", "aa", "ab", "ba", "ba", "ba", "ba", "bb", "bb", "bb", "bb", "bb"};
81
-        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(input);
82
-        String[] expected = new String[]{};
83
-        String[] actual = deleter.removeDuplicates(0);
84
-        TestUtils.assertArrayEquality(expected, actual);
85
-    }
86
-
87
-
88
-
89
-    @Test
90
-    public void testRemoveDuplicates1() {
91
-        String[] input = new String[]{"aa", "aa", "aa", "aa", "aa", "ab", "ba", "ba", "ba", "ba", "bb", "bb", "bb", "bb", "bb"};
92
-        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(input);
93
-        String[] expected = new String[]{};
94
-        String[] actual = deleter.removeDuplicates(1);
95
-        TestUtils.assertArrayEquality(expected, actual);
96
-    }
97
-
98
-
99
-    @Test
100
-    public void testRemoveDuplicates2() {
101
-        String[] input = new String[]{"aa", "aa", "aa", "aa", "aa", "ab", "ba", "ba", "ba", "ba", "bb", "bb", "bb", "bb", "bb"};
102
-        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(input);
103
-        String[] expected = new String[]{"ab"};
104
-        String[] actual = deleter.removeDuplicates(2);
105
-        TestUtils.assertArrayEquality(expected, actual);
106
-    }
107
-
108
-    @Test
109
-    public void testRemoveDuplicates3() {
110
-        String[] input = new String[]{"aa", "aa", "aa", "aa", "aa", "ab", "ba", "ba", "ba", "ba", "bb", "bb", "bb", "bb", "bb"};
111
-        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(input);
112
-        String[] expected = new String[]{"ab"};
113
-        String[] actual = deleter.removeDuplicates(3);
114
-        TestUtils.assertArrayEquality(expected, actual);
115
-    }
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-    @Test
137
-    public void testRemoveDuplicatesExactlyIdempotence() {
138
-        String[] input = RandomNumberFactory.createStrings('a', 'c', 2, 15);
139
-        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(input);
140
-        String[] expected = deleter.removeDuplicatesExactly(5);
141
-
142
-        for (int i = 0; i < input.length; i++) {
143
-            deleter.removeDuplicatesExactly(i);
144
-        }
145
-
146
-        String[] actual = deleter.removeDuplicatesExactly(5);
147
-
148
-        Arrays.sort(input);
149
-        System.out.println("Input:\n\t" + Arrays.toString(input));
150
-        TestUtils.assertArrayEquality(expected, actual);
151
-    }
152
-
153
-
154
-    @Test
155
-    public void testRemoveDuplicatesIdempotence() {
156
-        String[] input = RandomNumberFactory.createStrings('a', 'c', 2, 15);
157
-        DuplicateDeleter<String> deleter = new StringDuplicateDeleter(input);
158
-        String[] expected = deleter.removeDuplicates(5);
159
-
160
-        for (int i = 0; i < input.length; i++) {
161
-            deleter.removeDuplicates(i);
162
-        }
163
-
164
-        String[] actual = deleter.removeDuplicates(5);
165
-
166
-        Arrays.sort(input);
167
-        System.out.println("Input:\n\t" + Arrays.toString(input));
168
-        TestUtils.assertArrayEquality(expected, actual);
169
-    }
170
-
171
-}

+ 0
- 17
src/test/java/com/zipcodewilmington/looplabs/TestSuite.java Parādīt failu

@@ -1,17 +0,0 @@
1
-package com.zipcodewilmington.looplabs;
2
-
3
-import org.junit.runner.RunWith;
4
-import org.junit.runners.Suite;
5
-
6
-/**
7
- * Created by leon on 1/28/18.
8
- * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
9
- */
10
-@RunWith(Suite.class)
11
-
12
-@Suite.SuiteClasses({
13
-        IntegerDuplicateDeleterTest.class,
14
-        StringDuplicateDeleterTest.class
15
-})
16
-public class TestSuite {
17
-}

+ 0
- 26
src/test/java/com/zipcodewilmington/looplabs/TestUtils.java Parādīt failu

@@ -1,26 +0,0 @@
1
-package com.zipcodewilmington.looplabs;
2
-
3
-import org.junit.Assert;
4
-
5
-import java.util.Arrays;
6
-
7
-/**
8
- * Created by leon on 1/28/18.
9
- * @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
10
- */
11
-public class TestUtils {
12
-    public synchronized static <T, E> void assertArrayEquality(T[] expected, E[] actual) {
13
-        Arrays.sort(expected);
14
-        Arrays.sort(actual);
15
-        String expectedString = Arrays.toString(expected);
16
-        String actualString = Arrays.toString(actual);
17
-        boolean equality = expectedString.equals(actualString);
18
-
19
-        System.out.println("\n\nExpected:\n\t" + expectedString);
20
-        System.out.println("\nActual:\n\t" + actualString);
21
-        System.out.println("\nEquivalence:\n\t" + equality);
22
-
23
-        Assert.assertEquals(expectedString, actualString);
24
-        Assert.assertEquals(expected, actual);
25
-    }
26
-}