Froilan Miranda преди 6 години
ревизия
a39d779d1e
променени са 4 файла, в които са добавени 1931 реда и са изтрити 0 реда
  1. 115
    0
      .gitignore
  2. 1268
    0
      README.md
  3. 107
    0
      StringArrayUtils.java
  4. 441
    0
      StringArrayUtilsTest.java

+ 115
- 0
.gitignore Целия файл

1
+# Created by .ignore support plugin (hsz.mobi)
2
+### Java template
3
+# Compiled class file
4
+*.class
5
+
6
+# Log file
7
+*.log
8
+
9
+# BlueJ files
10
+*.ctxt
11
+
12
+# Mobile Tools for Java (J2ME)
13
+.mtj.tmp/
14
+
15
+# Package Files #
16
+*.jar
17
+*.war
18
+*.ear
19
+*.zip
20
+*.tar.gz
21
+*.rar
22
+
23
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24
+hs_err_pid*
25
+### Eclipse template
26
+
27
+.metadata
28
+bin/
29
+tmp/
30
+*.tmp
31
+*.bak
32
+*.swp
33
+*~.nib
34
+local.properties
35
+.settings/
36
+.loadpath
37
+.recommenders
38
+
39
+# Eclipse Core
40
+.project
41
+
42
+# External tool builders
43
+.externalToolBuilders/
44
+
45
+# Locally stored "Eclipse launch configurations"
46
+*.launch
47
+
48
+# PyDev specific (Python IDE for Eclipse)
49
+*.pydevproject
50
+
51
+# CDT-specific (C/C++ Development Tooling)
52
+.cproject
53
+
54
+# JDT-specific (Eclipse Java Development Tools)
55
+.classpath
56
+
57
+# Java annotation processor (APT)
58
+.factorypath
59
+
60
+# PDT-specific (PHP Development Tools)
61
+.buildpath
62
+
63
+# sbteclipse plugin
64
+.target
65
+
66
+# Tern plugin
67
+.tern-project
68
+
69
+# TeXlipse plugin
70
+.texlipse
71
+
72
+# STS (Spring Tool Suite)
73
+.springBeans
74
+
75
+# Code Recommenders
76
+.recommenders/
77
+
78
+# Scala IDE specific (Scala & Java development for Eclipse)
79
+.cache-main
80
+.scala_dependencies
81
+.worksheet
82
+### macOS template
83
+*.DS_Store
84
+.AppleDouble
85
+.LSOverride
86
+
87
+# Icon must end with two \r
88
+Icon
89
+
90
+
91
+# Thumbnails
92
+._*
93
+
94
+# Files that might appear in the root of a volume
95
+.DocumentRevisions-V100
96
+.fseventsd
97
+.Spotlight-V100
98
+.TemporaryItems
99
+.Trashes
100
+.VolumeIcon.icns
101
+.com.apple.timemachine.donotpresent
102
+
103
+# Directories potentially created on remote AFP share
104
+.AppleDB
105
+.AppleDesktop
106
+Network Trash Folder
107
+Temporary Items
108
+.apdisk
109
+
110
+#Intellij files
111
+.idea
112
+*.iml
113
+
114
+#maven build target
115
+target/

+ 1268
- 0
README.md
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 107
- 0
StringArrayUtils.java Целия файл

1
+package com.zipcodewilmington;
2
+
3
+/**
4
+ * Created by leon on 1/29/18.
5
+ */
6
+public class StringArrayUtils {
7
+    /**
8
+     * @param array array of String objects
9
+     * @return first element of specified array
10
+     */ // TODO
11
+    public static String getFirstElement(String[] array) {
12
+        return null;
13
+    }
14
+
15
+    /**
16
+     * @param array array of String objects
17
+     * @return second element in specified array
18
+     */
19
+    public static String getSecondElement(String[] array) {
20
+        return null;
21
+    }
22
+
23
+    /**
24
+     * @param array array of String objects
25
+     * @return last element in specified array
26
+     */ // TODO
27
+    public static String getLastElement(String[] array) {
28
+        return null;
29
+    }
30
+
31
+    /**
32
+     * @param array array of String objects
33
+     * @return second to last element in specified array
34
+     */ // TODO
35
+    public static String getSecondToLastElement(String[] array) {
36
+        return null;
37
+    }
38
+
39
+    /**
40
+     * @param array array of String objects
41
+     * @param value value to check array for
42
+     * @return true if the array contains the specified `value`
43
+     */ // TODO
44
+    public static boolean contains(String[] array, String value) {
45
+        return false;
46
+    }
47
+
48
+    /**
49
+     * @param array of String objects
50
+     * @return an array with identical contents in reverse order
51
+     */ // TODO
52
+    public static String[] reverse(String[] array) {
53
+        return null;
54
+    }
55
+
56
+    /**
57
+     * @param array array of String objects
58
+     * @return true if the order of the array is the same backwards and forwards
59
+     */ // TODO
60
+    public static boolean isPalindromic(String[] array) {
61
+        return false;
62
+    }
63
+
64
+    /**
65
+     * @param array array of String objects
66
+     * @return true if each letter in the alphabet has been used in the array
67
+     */ // TODO
68
+    public static boolean isPangramic(String[] array) {
69
+        return false;
70
+    }
71
+
72
+    /**
73
+     * @param array array of String objects
74
+     * @param value value to check array for
75
+     * @return number of occurrences the specified `value` has occurred
76
+     */ // TODO
77
+    public static int getNumberOfOccurrences(String[] array, String value) {
78
+        return 0;
79
+    }
80
+
81
+    /**
82
+     * @param array         array of String objects
83
+     * @param valueToRemove value to remove from array
84
+     * @return array with identical contents excluding values of `value`
85
+     */ // TODO
86
+    public static String[] removeValue(String[] array, String valueToRemove) {
87
+        return null;
88
+    }
89
+
90
+    /**
91
+     * @param array array of chars
92
+     * @return array of Strings with consecutive duplicates removes
93
+     */ // TODO
94
+    public static String[] removeConsecutiveDuplicates(String[] array) {
95
+        return null;
96
+    }
97
+
98
+    /**
99
+     * @param array array of chars
100
+     * @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings
101
+     */ // TODO
102
+    public static String[] packConsecutiveDuplicates(String[] array) {
103
+        return null;
104
+    }
105
+
106
+
107
+}

+ 441
- 0
StringArrayUtilsTest.java Целия файл

1
+package com.zipcodewilmington;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+/**
7
+ * Created by leon on 1/29/18.
8
+ */
9
+public class StringArrayUtilsTest {
10
+
11
+    @Test
12
+    public void testGetFirstElement1() {
13
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
14
+        String expected = "the";
15
+        String actual = StringArrayUtils.getFirstElement(array);
16
+        Assert.assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void testGetFirstElement2() {
21
+        String[] array = {"quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
22
+        String expected = "quick";
23
+        String actual = StringArrayUtils.getFirstElement(array);
24
+        Assert.assertEquals(expected, actual);
25
+    }
26
+
27
+
28
+    @Test
29
+    public void testGetFirstElement3() {
30
+        String[] array = {"brown", "fox", "jumps", "over", "the", "lazy", "dog"};
31
+        String expected = "brown";
32
+        String actual = StringArrayUtils.getFirstElement(array);
33
+        Assert.assertEquals(expected, actual);
34
+    }
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+    @Test
50
+    public void testGetSecondElement1() {
51
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
52
+        String expected = "quick";
53
+        String actual = StringArrayUtils.getSecondElement(array);
54
+        Assert.assertEquals(expected, actual);
55
+    }
56
+
57
+    @Test
58
+    public void testGetSecondElement2() {
59
+        String[] array = {"quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
60
+        String expected = "brown";
61
+        String actual = StringArrayUtils.getSecondElement(array);
62
+        Assert.assertEquals(expected, actual);
63
+    }
64
+
65
+
66
+    @Test
67
+    public void testGetSecondElement3() {
68
+        String[] array = {"brown", "fox", "jumps", "over", "the", "lazy", "dog"};
69
+        String expected = "fox";
70
+        String actual = StringArrayUtils.getSecondElement(array);
71
+        Assert.assertEquals(expected, actual);
72
+    }
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+    @Test
85
+    public void testGetLastElement1() {
86
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
87
+        String expected = "dog";
88
+        String actual = StringArrayUtils.getLastElement(array);
89
+        Assert.assertEquals(expected, actual);
90
+    }
91
+
92
+    @Test
93
+    public void testGetLastElement2() {
94
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy"};
95
+        String expected = "lazy";
96
+        String actual = StringArrayUtils.getLastElement(array);
97
+        Assert.assertEquals(expected, actual);
98
+    }
99
+
100
+
101
+    @Test
102
+    public void testGetLastElement3() {
103
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over"};
104
+        String expected = "over";
105
+        String actual = StringArrayUtils.getLastElement(array);
106
+        Assert.assertEquals(expected, actual);
107
+    }
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+    @Test
130
+    public void testGetSecondToLastElement1() {
131
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
132
+        String expected = "lazy";
133
+        String actual = StringArrayUtils.getSecondToLastElement(array);
134
+        Assert.assertEquals(expected, actual);
135
+    }
136
+
137
+    @Test
138
+    public void testGetSecondToLastElement2() {
139
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "lazy"};
140
+        String expected = "over";
141
+        String actual = StringArrayUtils.getSecondToLastElement(array);
142
+        Assert.assertEquals(expected, actual);
143
+    }
144
+
145
+
146
+    @Test
147
+    public void testGetSecondToLastElement3() {
148
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over"};
149
+        String expected = "jumps";
150
+        String actual = StringArrayUtils.getSecondToLastElement(array);
151
+        Assert.assertEquals(expected, actual);
152
+    }
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+    @Test
171
+    public void testContains() {
172
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
173
+        for (String s : array) {
174
+            boolean outcome = StringArrayUtils.contains(array, s);
175
+            Assert.assertTrue(outcome);
176
+        }
177
+    }
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+    @Test
192
+    public void testReverse1() {
193
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
194
+        String[] expected = {"dog", "lazy", "the", "over", "jumps", "fox", "brown", "quick", "the"};
195
+        String[] actual = StringArrayUtils.reverse(array);
196
+        Assert.assertEquals(expected, actual);
197
+    }
198
+
199
+
200
+    @Test
201
+    public void testReverse2() {
202
+        String[] array  = {"dog", "lazy", "the", "over", "jumps", "fox", "brown", "quick", "the"};
203
+        String[] expected = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
204
+        String[] actual = StringArrayUtils.reverse(array);
205
+        Assert.assertEquals(expected, actual);
206
+    }
207
+
208
+
209
+    @Test
210
+    public void testReverse3() {
211
+        String[] expected = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
212
+        String[] actual = StringArrayUtils.reverse(StringArrayUtils.reverse(expected));
213
+        Assert.assertEquals(expected, actual);
214
+    }
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+    @Test
226
+    public void testIsPalindromic1() {
227
+        String[] array = {"a", "b", "c", "b", "a"};
228
+        boolean outcome = StringArrayUtils.isPalindromic(array);
229
+        Assert.assertTrue(outcome);
230
+    }
231
+
232
+
233
+
234
+    @Test
235
+    public void testIsPalindromic2() {
236
+        String[] array = {"Is this a palindrome?", "This is a palindrome", "Is this a palindrome?"};
237
+        boolean outcome = StringArrayUtils.isPalindromic(array);
238
+        Assert.assertTrue(outcome);
239
+    }
240
+
241
+
242
+    @Test
243
+    public void testIsPalindromic3() {
244
+        String[] array = {"Is this a plaindrome?", "This is not a plaindrome", "Is this a palindrome?", "This is not a palindrome"};
245
+        boolean outcome = StringArrayUtils.isPalindromic(array);
246
+        Assert.assertFalse(outcome);
247
+    }
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+    @Test
258
+    public void testIsPangramic1() {
259
+        String[] array = {"The quick brown", "Fox jumps over", "The lazy dog"};
260
+        boolean outcome = StringArrayUtils.isPangramic(array);
261
+        Assert.assertTrue(outcome);
262
+    }
263
+
264
+    @Test
265
+    public void testIsPangramic2() {
266
+        String[] array = {"The", "quick", "onyx", "goblin", "jumps", "over", "the", "lazy", "dwarf"};
267
+        boolean outcome = StringArrayUtils.isPangramic(array);
268
+        Assert.assertTrue(outcome);
269
+    }
270
+
271
+    @Test
272
+    public void testIsPangramic3() {
273
+        String[] array = {"Five quacking", "zephyrs", "jolt my", "wax bed"};
274
+        boolean outcome = StringArrayUtils.isPangramic(array);
275
+        Assert.assertTrue(outcome);
276
+    }
277
+
278
+
279
+    @Test
280
+    public void testIsPangramic4() {
281
+        String[] array = {"a", "b", "c", "d"};
282
+        boolean outcome = StringArrayUtils.isPangramic(array);
283
+        Assert.assertFalse(outcome);
284
+    }
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+    @Test
299
+    public void testGetNumberOfOccurrences1() {
300
+        String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
301
+        int expected = 4;
302
+        int actual = StringArrayUtils.getNumberOfOccurrences(array, "bba");
303
+        Assert.assertEquals(actual, expected);
304
+    }
305
+
306
+    @Test
307
+    public void testGetNumberOfOccurrences2() {
308
+        String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
309
+        int expected = 2;
310
+        int actual = StringArrayUtils.getNumberOfOccurrences(array, "bbb");
311
+        Assert.assertEquals(actual, expected);
312
+    }
313
+
314
+    @Test
315
+    public void testGetNumberOfOccurrences3() {
316
+        String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
317
+        int expected = 4;
318
+        int actual = StringArrayUtils.getNumberOfOccurrences(array, "bba");
319
+        Assert.assertEquals(actual, expected);
320
+    }
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+    @Test
336
+    public void testRemoveConsecutiveDuplicates1() {
337
+        String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
338
+        String[] actual = StringArrayUtils.removeConsecutiveDuplicates(array);
339
+        String[] expected = {"aba", "baa", "bab", "bba", "bbb"};
340
+        Assert.assertEquals(actual, expected);
341
+    }
342
+
343
+
344
+
345
+    @Test
346
+    public void testRemoveConsecutiveDuplicates2() {
347
+        String[] array = {"aba", "aba", "baa", "bab", "bba", "zzz", "bba", "bba", "bba", "bbb", "bbb"};
348
+        String[] actual = StringArrayUtils.removeConsecutiveDuplicates(array);
349
+        String[] expected = {"aba", "baa", "bab", "bba", "zzz", "bba", "bbb"};
350
+        Assert.assertEquals(actual, expected);
351
+    }
352
+
353
+
354
+    @Test
355
+    public void testRemoveConsecutiveDuplicates3() {
356
+        String[] array = {"aba", "aba", "baa", "bab", "bba", "zzz", "bba", "bba", "bba", "aba", "bbb"};
357
+        String[] actual = StringArrayUtils.removeConsecutiveDuplicates(array);
358
+        String[] expected = {"aba", "baa", "bab", "bba", "zzz", "bba", "aba", "bbb"};
359
+        Assert.assertEquals(actual, expected);
360
+    }
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+    @Test
373
+    public void testRemovePackDuplicates1() {
374
+        String[] array = {"a", "a", "a", "b", "c", "c", "a", "a", "d"};
375
+        String[] expected = {"aaa", "b", "cc", "aa", "d"};
376
+        String[] actual = StringArrayUtils.packConsecutiveDuplicates(array);
377
+        Assert.assertEquals(expected, actual);
378
+    }
379
+
380
+
381
+    @Test
382
+    public void testRemovePackDuplicates2() {
383
+        String[] array = {"t", "t", "q", "a", "a", "a", "b", "c", "c", "a", "a", "d", "e", "e", "e"};
384
+        String[] expected = {"tt", "q", "aaa", "b", "cc", "aa", "d", "eee"};
385
+        String[] actual = StringArrayUtils.packConsecutiveDuplicates(array);
386
+        Assert.assertEquals(expected, actual);
387
+    }
388
+
389
+
390
+
391
+    @Test
392
+    public void testRemovePackDuplicates3() {
393
+        String[] array = {"m", "o", "o", "n", "m", "a", "n"};
394
+        String[] expected = {"m", "oo", "n", "m", "a", "n"};
395
+        String[] actual = StringArrayUtils.packConsecutiveDuplicates(array);
396
+        Assert.assertEquals(expected, actual);
397
+    }
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+    @Test
407
+    public void testRemoveValue() {
408
+        String[] array = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
409
+        String[] expected = {"quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
410
+        String[] actual = StringArrayUtils.removeValue(array, "The");
411
+        Assert.assertEquals(expected, actual);
412
+    }
413
+
414
+    @Test
415
+    public void testRemoveValue1() {
416
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
417
+        String[] expected = {"the", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
418
+        String[] actual = StringArrayUtils.removeValue(array, "quick");
419
+        Assert.assertEquals(expected, actual);
420
+    }
421
+
422
+    @Test
423
+    public void testRemoveValue2() {
424
+        String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
425
+        String[] expected = {"the", "quick", "fox", "jumps", "over", "the", "lazy", "dog"};
426
+        String[] actual = StringArrayUtils.removeValue(array, "brown");
427
+        Assert.assertEquals(expected, actual);
428
+    }
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+}