123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
-
-
- import org.junit.Assert;
- import org.junit.Test;
-
- /**
- * Created by leon on 1/29/18.
- */
- public class StringArrayUtilsTest {
-
- @Test
- public void testGetFirstElement1() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String expected = "the";
- String actual = StringArrayUtils.getFirstElement(array);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetFirstElement2() {
- String[] array = {"quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String expected = "quick";
- String actual = StringArrayUtils.getFirstElement(array);
- Assert.assertEquals(expected, actual);
- }
-
-
- @Test
- public void testGetFirstElement3() {
- String[] array = {"brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String expected = "brown";
- String actual = StringArrayUtils.getFirstElement(array);
- Assert.assertEquals(expected, actual);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @Test
- public void testGetSecondElement1() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String expected = "quick";
- String actual = StringArrayUtils.getSecondElement(array);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetSecondElement2() {
- String[] array = {"quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String expected = "brown";
- String actual = StringArrayUtils.getSecondElement(array);
- Assert.assertEquals(expected, actual);
- }
-
-
- @Test
- public void testGetSecondElement3() {
- String[] array = {"brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String expected = "fox";
- String actual = StringArrayUtils.getSecondElement(array);
- Assert.assertEquals(expected, actual);
- }
-
-
-
-
-
-
-
-
-
-
-
- @Test
- public void testGetLastElement1() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String expected = "dog";
- String actual = StringArrayUtils.getLastElement(array);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetLastElement2() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy"};
- String expected = "lazy";
- String actual = StringArrayUtils.getLastElement(array);
- Assert.assertEquals(expected, actual);
- }
-
-
- @Test
- public void testGetLastElement3() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over"};
- String expected = "over";
- String actual = StringArrayUtils.getLastElement(array);
- Assert.assertEquals(expected, actual);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @Test
- public void testGetSecondToLastElement1() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String expected = "lazy";
- String actual = StringArrayUtils.getSecondToLastElement(array);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testGetSecondToLastElement2() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "lazy"};
- String expected = "over";
- String actual = StringArrayUtils.getSecondToLastElement(array);
- Assert.assertEquals(expected, actual);
- }
-
-
- @Test
- public void testGetSecondToLastElement3() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over"};
- String expected = "jumps";
- String actual = StringArrayUtils.getSecondToLastElement(array);
- Assert.assertEquals(expected, actual);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @Test
- public void testContains() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- for (String s : array) {
- boolean outcome = StringArrayUtils.contains(array, s);
- Assert.assertTrue(outcome);
- }
- }
-
- @Test
- public void testContains1() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
-
- boolean outcome = StringArrayUtils.contains(array, "fox");
- Assert.assertTrue(outcome);
-
- }
-
-
-
-
-
-
-
-
-
-
-
- @Test
- public void testReverse1() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String[] expected = {"dog", "lazy", "the", "over", "jumps", "fox", "brown", "quick", "the"};
- String[] actual = StringArrayUtils.reverse(array);
- Assert.assertEquals(expected, actual);
- }
-
-
- @Test
- public void testReverse2() {
- String[] array = {"dog", "lazy", "the", "over", "jumps", "fox", "brown", "quick", "the"};
- String[] expected = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String[] actual = StringArrayUtils.reverse(array);
- Assert.assertEquals(expected, actual);
- }
-
-
- @Test
- public void testReverse3() {
- String[] expected = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String[] actual = StringArrayUtils.reverse(StringArrayUtils.reverse(expected));
- Assert.assertEquals(expected, actual);
- }
-
-
-
-
-
-
-
-
-
-
- @Test
- public void testIsPalindromic1() {
- String[] array = {"a", "b", "c", "b", "a"};
- boolean outcome = StringArrayUtils.isPalindromic(array);
- Assert.assertTrue(outcome);
- }
-
-
-
- @Test
- public void testIsPalindromic2() {
- String[] array = {"Is this a palindrome?", "This is a palindrome", "Is this a palindrome?"};
- boolean outcome = StringArrayUtils.isPalindromic(array);
- Assert.assertTrue(outcome);
- }
-
-
- @Test
- public void testIsPalindromic3() {
- String[] array = {"Is this a plaindrome?", "This is not a plaindrome", "Is this a palindrome?", "This is not a palindrome"};
- boolean outcome = StringArrayUtils.isPalindromic(array);
- Assert.assertFalse(outcome);
- }
-
-
-
-
-
-
-
-
-
- @Test
- public void testIsPangramic1() {
- String[] array = {"The quick brown", "Fox jumps over", "The lazy dog"};
- boolean outcome = StringArrayUtils.isPangramic(array);
- Assert.assertTrue(outcome);
- }
-
- @Test
- public void testIsPangramic2() {
- String[] array = {"The", "quick", "onyx", "goblin", "jumps", "over", "the", "lazy", "dwarf"};
- boolean outcome = StringArrayUtils.isPangramic(array);
- Assert.assertTrue(outcome);
- }
-
- @Test
- public void testIsPangramic3() {
- String[] array = {"Five quacking", "zephyrs", "jolt my", "wax bed"};
- boolean outcome = StringArrayUtils.isPangramic(array);
- Assert.assertTrue(outcome);
- }
-
-
- @Test
- public void testIsPangramic4() {
- String[] array = {"a", "b", "c", "d"};
- boolean outcome = StringArrayUtils.isPangramic(array);
- Assert.assertFalse(outcome);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- @Test
- public void testGetNumberOfOccurrences1() {
- String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
- int expected = 4;
- int actual = StringArrayUtils.getNumberOfOccurrences(array, "bba");
- Assert.assertEquals(actual, expected);
- }
-
- @Test
- public void testGetNumberOfOccurrences2() {
- String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
- int expected = 2;
- int actual = StringArrayUtils.getNumberOfOccurrences(array, "bbb");
- Assert.assertEquals(actual, expected);
- }
-
- @Test
- public void testGetNumberOfOccurrences3() {
- String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
- int expected = 4;
- int actual = StringArrayUtils.getNumberOfOccurrences(array, "bba");
- Assert.assertEquals(actual, expected);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @Test
- public void testRemoveConsecutiveDuplicates1() {
- String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
- String[] actual = StringArrayUtils.removeConsecutiveDuplicates(array);
- String[] expected = {"aba", "baa", "bab", "bba", "bbb"};
- Assert.assertEquals(actual, expected);
- }
-
-
-
- @Test
- public void testRemoveConsecutiveDuplicates2() {
- String[] array = {"aba", "aba", "baa", "bab", "bba", "zzz", "bba", "bba", "bba", "bbb", "bbb"};
- String[] actual = StringArrayUtils.removeConsecutiveDuplicates(array);
- String[] expected = {"aba", "baa", "bab", "bba", "zzz", "bba", "bbb"};
- Assert.assertEquals(actual, expected);
- }
-
-
- @Test
- public void testRemoveConsecutiveDuplicates3() {
- String[] array = {"aba", "aba", "baa", "bab", "bba", "zzz", "bba", "bba", "bba", "aba", "bbb"};
- String[] actual = StringArrayUtils.removeConsecutiveDuplicates(array);
- String[] expected = {"aba", "baa", "bab", "bba", "zzz", "bba", "aba", "bbb"};
- Assert.assertEquals(actual, expected);
- }
-
-
-
-
-
-
-
-
-
-
-
- @Test
- public void testRemovePackDuplicates1() {
- String[] array = {"a", "a", "a", "b", "c", "c", "a", "a", "d"};
- String[] expected = {"aaa", "b", "cc", "aa", "d"};
- String[] actual = StringArrayUtils.packConsecutiveDuplicates(array);
- Assert.assertEquals(expected, actual);
- }
-
-
- @Test
- public void testRemovePackDuplicates2() {
- String[] array = {"t", "t", "q", "a", "a", "a", "b", "c", "c", "a", "a", "d", "e", "e", "e"};
- String[] expected = {"tt", "q", "aaa", "b", "cc", "aa", "d", "eee"};
- String[] actual = StringArrayUtils.packConsecutiveDuplicates(array);
- Assert.assertEquals(expected, actual);
- }
-
-
-
- @Test
- public void testRemovePackDuplicates3() {
- String[] array = {"m", "o", "o", "n", "m", "a", "n"};
- String[] expected = {"m", "oo", "n", "m", "a", "n"};
- String[] actual = StringArrayUtils.packConsecutiveDuplicates(array);
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testRemovePackDuplicates4() {
- String[] array = {"m", "m", "o", "o", "n", "m", "a", "n"};
- String[] expected = {"mm", "oo", "n", "m", "a", "n"};
- String[] actual = StringArrayUtils.packConsecutiveDuplicates(array);
- Assert.assertEquals(expected, actual);
- }
-
-
-
-
-
-
- @Test
- public void testRemoveValue() {
- String[] array = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String[] expected = {"quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String[] actual = StringArrayUtils.removeValue(array, "The");
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testRemoveValue1() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String[] expected = {"the", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String[] actual = StringArrayUtils.removeValue(array, "quick");
- Assert.assertEquals(expected, actual);
- }
-
- @Test
- public void testRemoveValue2() {
- String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
- String[] expected = {"the", "quick", "fox", "jumps", "over", "the", "lazy", "dog"};
- String[] actual = StringArrayUtils.removeValue(array, "brown");
- Assert.assertEquals(expected, actual);
- }
-
-
-
-
-
-
-
-
-
-
-
-
- }
|