|
@@ -1,78 +1,77 @@
|
1
|
|
-
|
2
|
1
|
|
3
|
|
-import org.junit.Assert;
|
4
|
|
-import org.junit.Before;
|
5
|
|
-import org.junit.Test;
|
6
|
2
|
|
7
|
|
-import java.util.Arrays;
|
|
3
|
+ import org.junit.Assert;
|
|
4
|
+ import org.junit.Before;
|
|
5
|
+ import org.junit.Test;
|
8
|
6
|
|
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 {
|
|
7
|
+ import java.util.Arrays;
|
14
|
8
|
|
15
|
|
- @Test
|
16
|
|
- public void testRemoveDuplicatesExactly_whenThereIsOnlyOneElement() {
|
17
|
|
- Integer[] intArray = new Integer[]{0};
|
18
|
|
- DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
|
|
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 {
|
19
|
14
|
|
20
|
|
- Integer[] expected = new Integer[]{0};
|
21
|
|
- Integer[] actual = deleter.removeDuplicatesExactly(2);
|
22
|
|
- Assert.assertArrayEquals(expected, actual);
|
23
|
|
- }
|
|
15
|
+ @Test
|
|
16
|
+ public void testRemoveDuplicatesExactly_whenThereIsOnlyOneElement() {
|
|
17
|
+ Integer[] intArray = new Integer[]{0};
|
|
18
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
|
24
|
19
|
|
25
|
|
- @Test
|
26
|
|
- public void testRemoveDuplicatesExactly_whenThereIsOnlyOneElementAndRemoveDumplicationIs1() {
|
27
|
|
- Integer[] intArray = new Integer[]{9};
|
28
|
|
- DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
|
|
20
|
+ Integer[] expected = new Integer[]{0};
|
|
21
|
+ Integer[] actual = deleter.removeDuplicatesExactly(2);
|
|
22
|
+ Assert.assertArrayEquals(expected, actual);
|
|
23
|
+ }
|
29
|
24
|
|
30
|
|
- Integer[] expected = new Integer[]{};
|
31
|
|
- Integer[] actual = deleter.removeDuplicatesExactly(1);
|
32
|
|
- Assert.assertArrayEquals(expected, actual);
|
33
|
|
- }
|
|
25
|
+ @Test
|
|
26
|
+ public void testRemoveDuplicatesExactly_whenThereIsOnlyOneElementAndRemoveDumplicationIs1() {
|
|
27
|
+ Integer[] intArray = new Integer[]{9};
|
|
28
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
|
34
|
29
|
|
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);
|
|
30
|
+ Integer[] expected = new Integer[]{};
|
|
31
|
+ Integer[] actual = deleter.removeDuplicatesExactly(1);
|
|
32
|
+ Assert.assertArrayEquals(expected, actual);
|
|
33
|
+ }
|
39
|
34
|
|
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
|
|
- }
|
|
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);
|
44
|
39
|
|
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);
|
|
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
|
+ }
|
49
|
44
|
|
50
|
|
- Integer[] expected = new Integer[]{1, 3, 3, 3};
|
51
|
|
- Integer[] actual = deleter.removeDuplicatesExactly(2);
|
52
|
|
- Assert.assertArrayEquals(expected, actual);
|
53
|
|
- }
|
|
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);
|
54
|
49
|
|
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);
|
|
50
|
+ Integer[] expected = new Integer[]{1, 3, 3, 3};
|
|
51
|
+ Integer[] actual = deleter.removeDuplicatesExactly(2);
|
|
52
|
+ Assert.assertArrayEquals(expected, actual);
|
|
53
|
+ }
|
59
|
54
|
|
60
|
|
- Integer[] expected = new Integer[]{1, 2, 2, 4, 4, 6};
|
61
|
|
- Integer[] actual = deleter.removeDuplicatesExactly(3);
|
62
|
|
- Assert.assertArrayEquals(expected, actual);
|
63
|
|
- }
|
|
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);
|
64
|
59
|
|
|
60
|
+ Integer[] expected = new Integer[]{1, 2, 2, 4, 4, 6};
|
|
61
|
+ Integer[] actual = deleter.removeDuplicatesExactly(3);
|
|
62
|
+ Assert.assertArrayEquals(expected, actual);
|
|
63
|
+ }
|
65
|
64
|
|
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
|
65
|
|
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
|
|
- }
|
|
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);
|
75
|
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
|
+ }
|
76
|
75
|
|
77
|
76
|
|
78
|
77
|
|
|
@@ -82,108 +81,113 @@ public class IntegerDuplicateDeleterTest {
|
82
|
81
|
|
83
|
82
|
|
84
|
83
|
|
85
|
|
- @Test
|
86
|
|
- public void testRemoveDuplicates_whenThereIsOnlyOneElement() {
|
87
|
|
- Integer[] intArray = new Integer[]{5};
|
88
|
|
- DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
|
89
|
84
|
|
90
|
|
- Integer[] expected = new Integer[]{5};
|
91
|
|
- Integer[] actual = deleter.removeDuplicates(2);
|
92
|
|
- Assert.assertArrayEquals(expected, actual);
|
93
|
|
- }
|
|
85
|
+ @Test
|
|
86
|
+ public void testRemoveDuplicates_whenThereIsOnlyOneElement() {
|
|
87
|
+ Integer[] intArray = new Integer[]{5};
|
|
88
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
|
94
|
89
|
|
95
|
|
- @Test
|
96
|
|
- public void testRemoveDuplicates_whenThereIsOnlyOneElementAndRemoveDumplicationIs1() {
|
97
|
|
- Integer[] intArray = new Integer[]{3};
|
98
|
|
- DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
|
|
90
|
+ Integer[] expected = new Integer[]{5};
|
|
91
|
+ Integer[] actual = deleter.removeDuplicates(2);
|
|
92
|
+ Assert.assertArrayEquals(expected, actual);
|
|
93
|
+ }
|
99
|
94
|
|
100
|
|
- Integer[] expected = new Integer[]{};
|
101
|
|
- Integer[] actual = deleter.removeDuplicatesExactly(1);
|
102
|
|
- Assert.assertArrayEquals(expected, actual);
|
103
|
|
- }
|
|
95
|
+ @Test
|
|
96
|
+ public void testRemoveDuplicates_whenThereIsOnlyOneElementAndRemoveDumplicationIs1() {
|
|
97
|
+ Integer[] intArray = new Integer[]{3};
|
|
98
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
|
104
|
99
|
|
105
|
|
- @Test
|
106
|
|
- public void testRemoveDuplicates_whenThereIsMoreThanOneElement() {
|
107
|
|
- Integer[] intArray = new Integer[]{4, 1, 2};
|
108
|
|
- DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
|
|
100
|
+ Integer[] expected = new Integer[]{};
|
|
101
|
+ Integer[] actual = deleter.removeDuplicatesExactly(1);
|
|
102
|
+ Assert.assertArrayEquals(expected, actual);
|
|
103
|
+ }
|
109
|
104
|
|
110
|
|
- Integer[] expected = new Integer[]{4, 1, 2};
|
111
|
|
- Integer[] actual = deleter.removeDuplicates(2);
|
112
|
|
- Assert.assertArrayEquals(expected, actual);
|
113
|
|
- }
|
|
105
|
+ @Test
|
|
106
|
+ public void testRemoveDuplicates_whenThereIsMoreThanOneElement() {
|
|
107
|
+ Integer[] intArray = new Integer[]{4, 1, 2};
|
|
108
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(intArray);
|
114
|
109
|
|
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);
|
|
110
|
+ Integer[] expected = new Integer[]{4, 1, 2};
|
|
111
|
+ Integer[] actual = deleter.removeDuplicates(2);
|
|
112
|
+ Assert.assertArrayEquals(expected, actual);
|
|
113
|
+ }
|
119
|
114
|
|
120
|
|
- Integer[] expected = new Integer[]{1};
|
121
|
|
- Integer[] actual = deleter.removeDuplicates(2);
|
122
|
|
- Assert.assertArrayEquals(expected, actual);
|
123
|
|
- }
|
|
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);
|
124
|
119
|
|
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
|
|
- }
|
|
120
|
+ Integer[] expected = new Integer[]{1};
|
|
121
|
+ Integer[] actual = deleter.removeDuplicates(2);
|
|
122
|
+ Assert.assertArrayEquals(expected, actual);
|
|
123
|
+ }
|
133
|
124
|
|
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
|
|
- }
|
|
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
|
+ }
|
142
|
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
|
+ }
|
143
|
142
|
|
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
|
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
|
+ }
|
153
|
152
|
|
154
|
153
|
|
155
|
154
|
|
156
|
155
|
|
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
|
156
|
|
162
|
|
- DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(input);
|
|
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};
|
163
|
161
|
|
164
|
|
- Integer[] actual1 = deleter.removeDuplicatesExactly(3);
|
165
|
|
- Integer[] actual2 = deleter.removeDuplicatesExactly(3);
|
166
|
|
- Integer[] actual3 = deleter.removeDuplicatesExactly(3);
|
|
162
|
+ DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(input);
|
167
|
163
|
|
168
|
|
- Assert.assertArrayEquals(expected, actual1);
|
169
|
|
- Assert.assertArrayEquals(expected, actual2);
|
170
|
|
- Assert.assertArrayEquals(expected, actual3);
|
171
|
|
- }
|
|
164
|
+ Integer[] actual1 = deleter.removeDuplicatesExactly(3);
|
|
165
|
+ Integer[] actual2 = deleter.removeDuplicatesExactly(3);
|
|
166
|
+ Integer[] actual3 = deleter.removeDuplicatesExactly(3);
|
172
|
167
|
|
|
168
|
+ Assert.assertArrayEquals(expected, actual1);
|
|
169
|
+ Assert.assertArrayEquals(expected, actual2);
|
|
170
|
+ Assert.assertArrayEquals(expected, actual3);
|
|
171
|
+ }
|
173
|
172
|
|
174
|
|
- @Test
|
175
|
|
- public void testRemoveDuplicatesIdempotence() {
|
176
|
|
- Integer[] input = {1, 2, 2, 2, 3, 4, 4};
|
177
|
|
- Integer[] expected = {1, 3};
|
178
|
173
|
|
179
|
|
- DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(input);
|
|
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
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+ }
|
180
|
193
|
|
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
|
|
-}
|