From e774303ceca88e218dfc7d8f46a5d5b67071a9df Mon Sep 17 00:00:00 2001 From: Alexander Leali Date: Sat, 29 Mar 2025 15:34:02 -0400 Subject: [PATCH 1/9] Wrote test for the capitalize method, the tests ensure that the method capitalizes character a-z --- .../apache/commons/text/myCaseUtilsTests.java | 0 .../java/org/apache/commons/text/myTests.java | 0 .../commons/text/myWordsUtilsTests.java | 38 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/test/java/org/apache/commons/text/myCaseUtilsTests.java create mode 100644 src/test/java/org/apache/commons/text/myTests.java create mode 100644 src/test/java/org/apache/commons/text/myWordsUtilsTests.java diff --git a/src/test/java/org/apache/commons/text/myCaseUtilsTests.java b/src/test/java/org/apache/commons/text/myCaseUtilsTests.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/java/org/apache/commons/text/myTests.java b/src/test/java/org/apache/commons/text/myTests.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java new file mode 100644 index 0000000000..1ee3a0a5ac --- /dev/null +++ b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java @@ -0,0 +1,38 @@ +package org.apache.commons.text; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvFileSource; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.api.Test; +public class myWordsUtilsTests { + //variables for whitespaced capitalization + private static String typicalSentence = "The quick brown fox jumps over the lazy dog"; + private static String[] whitespaceSelective = {" thequickbrownfoxjumpsoverthelazydog", "the quickbrownfoxjumpsoverthelazydog", "thequick brownfoxjumpsoverthelazydog", "thequickbrown foxjumpsoverthelazydog", "thequickbrownfox jumpsoverthelazydog", "thequickbrownfoxjumps overthelazydog", "thequickbrownfoxjumpsover thelazydog", "thequickbrownfoxjumpsoverthe lazydog", "thequickbrownfoxjumpsoverthelazy dog", "thequickbrownfoxjumpsoverthelazydog "}; + private static String[] expectedWhitespaceSelective = {" Thequickbrownfoxjumpsoverthelazydog", "The Quickbrownfoxjumpsoverthelazydog", "Thequick Brownfoxjumpsoverthelazydog", "Thequickbrown Foxjumpsoverthelazydog", "Thequickbrownfox Jumpsoverthelazydog", "Thequickbrownfoxjumps Overthelazydog", "Thequickbrownfoxjumpsover Thelazydog", "Thequickbrownfoxjumpsoverthe Lazydog", "Thequickbrownfoxjumpsoverthelazy Dog", "Thequickbrownfoxjumpsoverthelazydog "}; + + //variables for delimited capitalization + private static String delimiters = "!@#$%^&*("; + private static String vowels= "aeiou"; + private static String delimitedSentence = "!the @quick #brown $fox %jumps ^over &the *lazy (dog"; + private static String[] expectedDelimitedSentences = {"!The @quick #brown $fox %jumps ^over &the *lazy (dog", "!the @Quick #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #Brown $fox %jumps ^over &the *lazy (dog", "!the @quick #brown $Fox %jumps ^over &the *lazy (dog", "!the @quick #brown $fox %Jumps ^over &the *lazy (dog", "!the @quick #brown $fox %jumps ^Over &the *lazy (dog", "!the @quick #brown $fox %jumps ^over &The *lazy (dog", "!the @quick #brown $fox %jumps ^over &the *Lazy (dog", "!the @quick #brown $fox %jumps ^over &the *lazy (Dog"}; + private static String[] expectedVoweledSentences = {"!the @quick #brown $fox %jumps ^over &the *laZy (dog", "!the @quick #brown $fox %jumps ^oveR &the *lazy (dog", "!the @quiCk #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #broWn $foX %jumps ^oVer &the *lazy (doG", "!the @quIck #brown $fox %juMps ^over &the *lazy (dog"}; + + @Test + public void whitespaceCaptializeTest() { + assertEquals("!@#$%^&*()_+", WordUtils.capitalize("!@#$%^&*()_+")); + assertEquals("!the @quick #brown $fox %jumps ^over &the *lazy (dog", WordUtils.capitalize(delimitedSentence)); + assertEquals("The Quick Brown Fox Jumps Over The Lazy Dog", WordUtils.capitalize(typicalSentence)); + for (int x = 0; x < whitespaceSelective.length - 1; x++) { + assertEquals(expectedWhitespaceSelective[x], WordUtils.capitalize(whitespaceSelective[x])); + } + } + + +} From 37a74d3949bb45edc0413dbe12052e431b07816a Mon Sep 17 00:00:00 2001 From: Alexander Leali Date: Sat, 29 Mar 2025 15:35:19 -0400 Subject: [PATCH 2/9] Wrote test for the capitalize method, it uses the overloaded version that requres a delimiter. it checks for a null delimiter, special characters, vowels --- .../org/apache/commons/text/myWordsUtilsTests.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java index 1ee3a0a5ac..f70a52a07f 100644 --- a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java +++ b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java @@ -34,5 +34,17 @@ public void whitespaceCaptializeTest() { } } + @Test + public void delimiterCapitalizeTest(){ + assertEquals("!the @quick #brown $fox %jumps ^over &the *lazy (dog", WordUtils.capitalize(delimitedSentence, null)); + for (int x = 0; x < delimiters.length()-1; x++) { + assertEquals(expectedDelimitedSentences[x], WordUtils.capitalize(delimitedSentence, delimiters.charAt(x))); + } + for (int x = 0; x < vowels.length()-1; x++) { + assertEquals(expectedVoweledSentences[x], WordUtils.capitalize(delimitedSentence, vowels.charAt(x))); + } + + } + } From 39d6e4f5e40749e1ca8826324b0469393eaec991 Mon Sep 17 00:00:00 2001 From: Alexander Leali Date: Thu, 10 Apr 2025 12:58:57 -0400 Subject: [PATCH 3/9] added license to the test file --- .../apache/commons/text/myCaseUtilsTests.java | 0 .../commons/text/myWordsUtilsTests.java | 28 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) delete mode 100644 src/test/java/org/apache/commons/text/myCaseUtilsTests.java diff --git a/src/test/java/org/apache/commons/text/myCaseUtilsTests.java b/src/test/java/org/apache/commons/text/myCaseUtilsTests.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java index f70a52a07f..b8654da2b1 100644 --- a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java +++ b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java @@ -1,7 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.commons.text; import static org.junit.jupiter.api.Assertions.assertEquals; - +import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.BeforeEach; @@ -24,6 +40,8 @@ public class myWordsUtilsTests { private static String[] expectedDelimitedSentences = {"!The @quick #brown $fox %jumps ^over &the *lazy (dog", "!the @Quick #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #Brown $fox %jumps ^over &the *lazy (dog", "!the @quick #brown $Fox %jumps ^over &the *lazy (dog", "!the @quick #brown $fox %Jumps ^over &the *lazy (dog", "!the @quick #brown $fox %jumps ^Over &the *lazy (dog", "!the @quick #brown $fox %jumps ^over &The *lazy (dog", "!the @quick #brown $fox %jumps ^over &the *Lazy (dog", "!the @quick #brown $fox %jumps ^over &the *lazy (Dog"}; private static String[] expectedVoweledSentences = {"!the @quick #brown $fox %jumps ^over &the *laZy (dog", "!the @quick #brown $fox %jumps ^oveR &the *lazy (dog", "!the @quiCk #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #broWn $foX %jumps ^oVer &the *lazy (doG", "!the @quIck #brown $fox %juMps ^over &the *lazy (dog"}; + private static String sentenceForAbreviation = "One day work will end, play is forever! One day play will end, work is forever!"; + @Test public void whitespaceCaptializeTest() { assertEquals("!@#$%^&*()_+", WordUtils.capitalize("!@#$%^&*()_+")); @@ -45,6 +63,14 @@ public void delimiterCapitalizeTest(){ } } + @Test + public void abreviateTest(){ + assertEquals("One day work will end, play is forever! ... I'll find some way to end this.", WordUtils.abbreviate(sentenceForAbreviation, '!', -1, "... I'll find some way to end this." )); + assertEquals("One day work will end, play is forever! One day play will end, w #-%", WordUtils.abbreviate(sentenceForAbreviation, 'A', 'Z', "#-%" )); + assertEquals("One day work will end, play is forever! One day play will end, work is forever! Nothing seemed to be abbreviated here.", WordUtils.abbreviate(sentenceForAbreviation, 'a', 'z', "Nothing seemed to be abbreviated here." )); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, -1, -1, "... I'll find some way to end this." )); + + } } From 074642100165a1c5519f65b0e5d0245796ada929 Mon Sep 17 00:00:00 2001 From: Alexander Leali Date: Thu, 10 Apr 2025 15:15:59 -0400 Subject: [PATCH 4/9] removed in progress tests for clarity on current progress of project --- .../org/apache/commons/text/myWordsUtilsTests.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java index b8654da2b1..51cbe612a1 100644 --- a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java +++ b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java @@ -44,6 +44,7 @@ public class myWordsUtilsTests { @Test public void whitespaceCaptializeTest() { + //partiton testing assertEquals("!@#$%^&*()_+", WordUtils.capitalize("!@#$%^&*()_+")); assertEquals("!the @quick #brown $fox %jumps ^over &the *lazy (dog", WordUtils.capitalize(delimitedSentence)); assertEquals("The Quick Brown Fox Jumps Over The Lazy Dog", WordUtils.capitalize(typicalSentence)); @@ -54,6 +55,7 @@ public void whitespaceCaptializeTest() { @Test public void delimiterCapitalizeTest(){ + //partition testing assertEquals("!the @quick #brown $fox %jumps ^over &the *lazy (dog", WordUtils.capitalize(delimitedSentence, null)); for (int x = 0; x < delimiters.length()-1; x++) { assertEquals(expectedDelimitedSentences[x], WordUtils.capitalize(delimitedSentence, delimiters.charAt(x))); @@ -63,14 +65,6 @@ public void delimiterCapitalizeTest(){ } } - @Test - public void abreviateTest(){ - assertEquals("One day work will end, play is forever! ... I'll find some way to end this.", WordUtils.abbreviate(sentenceForAbreviation, '!', -1, "... I'll find some way to end this." )); - assertEquals("One day work will end, play is forever! One day play will end, w #-%", WordUtils.abbreviate(sentenceForAbreviation, 'A', 'Z', "#-%" )); - assertEquals("One day work will end, play is forever! One day play will end, work is forever! Nothing seemed to be abbreviated here.", WordUtils.abbreviate(sentenceForAbreviation, 'a', 'z', "Nothing seemed to be abbreviated here." )); - assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, -1, -1, "... I'll find some way to end this." )); - - } - + } From e815658d84587e2ad10c384ec4845178929c0722 Mon Sep 17 00:00:00 2001 From: Alexander Leali Date: Sat, 19 Apr 2025 15:25:54 -0400 Subject: [PATCH 5/9] parametized inputs and seperated assertions into individual test functions --- .../commons/text/myWordsUtilsTests.java | 148 +++++++++++++++--- 1 file changed, 127 insertions(+), 21 deletions(-) diff --git a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java index 51cbe612a1..e2904e1678 100644 --- a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java +++ b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java @@ -27,44 +27,150 @@ import org.junit.jupiter.params.provider.CsvFileSource; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.api.Test; + public class myWordsUtilsTests { //variables for whitespaced capitalization - private static String typicalSentence = "The quick brown fox jumps over the lazy dog"; - private static String[] whitespaceSelective = {" thequickbrownfoxjumpsoverthelazydog", "the quickbrownfoxjumpsoverthelazydog", "thequick brownfoxjumpsoverthelazydog", "thequickbrown foxjumpsoverthelazydog", "thequickbrownfox jumpsoverthelazydog", "thequickbrownfoxjumps overthelazydog", "thequickbrownfoxjumpsover thelazydog", "thequickbrownfoxjumpsoverthe lazydog", "thequickbrownfoxjumpsoverthelazy dog", "thequickbrownfoxjumpsoverthelazydog "}; - private static String[] expectedWhitespaceSelective = {" Thequickbrownfoxjumpsoverthelazydog", "The Quickbrownfoxjumpsoverthelazydog", "Thequick Brownfoxjumpsoverthelazydog", "Thequickbrown Foxjumpsoverthelazydog", "Thequickbrownfox Jumpsoverthelazydog", "Thequickbrownfoxjumps Overthelazydog", "Thequickbrownfoxjumpsover Thelazydog", "Thequickbrownfoxjumpsoverthe Lazydog", "Thequickbrownfoxjumpsoverthelazy Dog", "Thequickbrownfoxjumpsoverthelazydog "}; + private static String typicalSentence; + private static String[] whitespaceSelective; + private static String[] expectedWhitespaceSelective; //variables for delimited capitalization - private static String delimiters = "!@#$%^&*("; - private static String vowels= "aeiou"; - private static String delimitedSentence = "!the @quick #brown $fox %jumps ^over &the *lazy (dog"; - private static String[] expectedDelimitedSentences = {"!The @quick #brown $fox %jumps ^over &the *lazy (dog", "!the @Quick #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #Brown $fox %jumps ^over &the *lazy (dog", "!the @quick #brown $Fox %jumps ^over &the *lazy (dog", "!the @quick #brown $fox %Jumps ^over &the *lazy (dog", "!the @quick #brown $fox %jumps ^Over &the *lazy (dog", "!the @quick #brown $fox %jumps ^over &The *lazy (dog", "!the @quick #brown $fox %jumps ^over &the *Lazy (dog", "!the @quick #brown $fox %jumps ^over &the *lazy (Dog"}; - private static String[] expectedVoweledSentences = {"!the @quick #brown $fox %jumps ^over &the *laZy (dog", "!the @quick #brown $fox %jumps ^oveR &the *lazy (dog", "!the @quiCk #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #broWn $foX %jumps ^oVer &the *lazy (doG", "!the @quIck #brown $fox %juMps ^over &the *lazy (dog"}; + private static String delimiters; + private static String vowels; + private static String delimitedSentence; + private static String[] expectedDelimitedSentences; + private static String[] expectedVoweledSentences; - private static String sentenceForAbreviation = "One day work will end, play is forever! One day play will end, work is forever!"; + private static String sentenceForAbreviation; - @Test - public void whitespaceCaptializeTest() { - //partiton testing - assertEquals("!@#$%^&*()_+", WordUtils.capitalize("!@#$%^&*()_+")); - assertEquals("!the @quick #brown $fox %jumps ^over &the *lazy (dog", WordUtils.capitalize(delimitedSentence)); - assertEquals("The Quick Brown Fox Jumps Over The Lazy Dog", WordUtils.capitalize(typicalSentence)); - for (int x = 0; x < whitespaceSelective.length - 1; x++) { - assertEquals(expectedWhitespaceSelective[x], WordUtils.capitalize(whitespaceSelective[x])); - } + @BeforeAll + public static void setUp(){ + typicalSentence = "The quick brown fox jumps over the lazy dog"; + delimiters = "!@#$%^&*("; + vowels= "aeiou"; + delimitedSentence = "!the @quick #brown $fox %jumps ^over &the *lazy (dog"; + whitespaceSelective = new String[]{" thequickbrownfoxjumpsoverthelazydog", "the quickbrownfoxjumpsoverthelazydog", "thequick brownfoxjumpsoverthelazydog", "thequickbrown foxjumpsoverthelazydog", "thequickbrownfox jumpsoverthelazydog", "thequickbrownfoxjumps overthelazydog", "thequickbrownfoxjumpsover thelazydog", "thequickbrownfoxjumpsoverthe lazydog", "thequickbrownfoxjumpsoverthelazy dog", "thequickbrownfoxjumpsoverthelazydog "}; + expectedWhitespaceSelective = new String[]{" Thequickbrownfoxjumpsoverthelazydog", "The Quickbrownfoxjumpsoverthelazydog", "Thequick Brownfoxjumpsoverthelazydog", "Thequickbrown Foxjumpsoverthelazydog", "Thequickbrownfox Jumpsoverthelazydog", "Thequickbrownfoxjumps Overthelazydog", "Thequickbrownfoxjumpsover Thelazydog", "Thequickbrownfoxjumpsoverthe Lazydog", "Thequickbrownfoxjumpsoverthelazy Dog", "Thequickbrownfoxjumpsoverthelazydog "}; + expectedDelimitedSentences = new String[]{"!The @quick #brown $fox %jumps ^over &the *lazy (dog", "!the @Quick #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #Brown $fox %jumps ^over &the *lazy (dog", "!the @quick #brown $Fox %jumps ^over &the *lazy (dog", "!the @quick #brown $fox %Jumps ^over &the *lazy (dog", "!the @quick #brown $fox %jumps ^Over &the *lazy (dog", "!the @quick #brown $fox %jumps ^over &The *lazy (dog", "!the @quick #brown $fox %jumps ^over &the *Lazy (dog", "!the @quick #brown $fox %jumps ^over &the *lazy (Dog"}; + expectedVoweledSentences = new String[]{"!the @quick #brown $fox %jumps ^over &the *laZy (dog", "!the @quick #brown $fox %jumps ^oveR &the *lazy (dog", "!the @quiCk #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #broWn $foX %jumps ^oVer &the *lazy (doG", "!the @quIck #brown $fox %juMps ^over &the *lazy (dog"}; + sentenceForAbreviation = "One day work will end, play is forever! One day play will end, work is forever!"; } + //partiton testing + @Test + public void whitespaceCaptializeTestNoLetters() { assertEquals("!@#$%^&*()_+", WordUtils.capitalize("!@#$%^&*()_+")); } + @Test - public void delimiterCapitalizeTest(){ - //partition testing - assertEquals("!the @quick #brown $fox %jumps ^over &the *lazy (dog", WordUtils.capitalize(delimitedSentence, null)); + public void whitespaceCapitalizeTestLettersPrefixedWithSymbols(){ assertEquals("!the @quick #brown $fox %jumps ^over &the *lazy (dog", WordUtils.capitalize(delimitedSentence)); } + + @Test + public void whitespaceCapitalizeTestTypical(){ assertEquals("The Quick Brown Fox Jumps Over The Lazy Dog", WordUtils.capitalize(typicalSentence)); } + + @Test + public void delimiterCapitalizeTestWithNoDelimiters(){ assertEquals("!the @quick #brown $fox %jumps ^over &the *lazy (dog", WordUtils.capitalize(delimitedSentence, null)); } + + + @Test + public void delimiterCapitalizeTestWithSymbolDelimiters(){ for (int x = 0; x < delimiters.length()-1; x++) { assertEquals(expectedDelimitedSentences[x], WordUtils.capitalize(delimitedSentence, delimiters.charAt(x))); } + } + + @Test + public void delimiterCapitalizeTestWithVowelDelimiters(){ for (int x = 0; x < vowels.length()-1; x++) { assertEquals(expectedVoweledSentences[x], WordUtils.capitalize(delimitedSentence, vowels.charAt(x))); } + } + + @Test + public void abreviateTest(){ + //robust worst case boundary testing + // lower: min to min+1, upper: min-1 + assertEquals("One... I'll find some way to end this.", WordUtils.abbreviate(sentenceForAbreviation, -1, -1, "... I'll find some way to end this." )); + assertEquals("One...You will relive every key mistake you've ever made in your life.", WordUtils.abbreviate(sentenceForAbreviation, 0, -1, "...You will relive every key mistake you've ever made in your life.")); + assertEquals("One...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, 1, -1, "...We are indeed close.")); + + // lower: min-1 to min+1, upper: min + assertEquals("...Where did the sentence go?", WordUtils.abbreviate(sentenceForAbreviation, -1, 0, "...Where did the sentence go?" )); + assertEquals("...There's nothing there.", WordUtils.abbreviate(sentenceForAbreviation, 0, 0, "...There's nothing there.")); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 1, 0, "...Oops, that's an exception.")); + + // lower: min-1 to min+1, upper: min+1 + assertEquals("O...Oh!", WordUtils.abbreviate(sentenceForAbreviation, -1, 1, "...Oh!" )); + assertEquals("O, Oh...", WordUtils.abbreviate(sentenceForAbreviation, 0, 1, ", Oh...")); + assertEquals("O...what about U?", WordUtils.abbreviate(sentenceForAbreviation, 1, 1, "...what about U?")); + + // lower: min-1 to min+1, upper: typical + assertEquals("One...huh?", WordUtils.abbreviate(sentenceForAbreviation, -1, 20, "...huh?" )); + assertEquals("One...what?", WordUtils.abbreviate(sentenceForAbreviation, 0, 'Z', "...what?")); + assertEquals("One...why?", WordUtils.abbreviate(sentenceForAbreviation, 1, 'z', "...why?")); + + // lower: min-1 to min+1, upper: max-1 + assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, -1, Integer.MAX_VALUE-1, "" )); + assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, 0, Integer.MAX_VALUE-1, "")); + assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, 1, Integer.MAX_VALUE-1, "")); + + // lower: min-1 to min+1, upper: max + assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, -1, Integer.MAX_VALUE, "" )); + assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, 0, Integer.MAX_VALUE, "")); + assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, 1, Integer.MAX_VALUE, "")); + + // lower: min-1 to min+1, upper: max+1 + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, -1, Integer.MAX_VALUE+1, "" )); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 0, Integer.MAX_VALUE+1, "")); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 1, Integer.MAX_VALUE+1, "")); + + // lower: typical, upper: min-1 to min+1 + assertEquals("One day work will end, play is forever!... I'll find some way to end this.", WordUtils.abbreviate(sentenceForAbreviation, '!', -1, "... I'll find some way to end this." )); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 'A', 0, "#-%" )); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 'a', 1, "Nothing seemed to be abbreviated here." )); + + // lower: typical, upper: typical + assertEquals("One day work will end, play is forever! One day play will end, work#-%", WordUtils.abbreviate(sentenceForAbreviation, 'A', 'Z', "#-%" )); + + // lower: typical, upper: max-1 to max+1 + assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, 'a', Integer.MAX_VALUE-1, " Nothing seemed to be abbreviated here." )); + assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, 'a', Integer.MAX_VALUE, " Nothing seemed to be abbreviated here." )); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 'a', Integer.MAX_VALUE+1, "Nothing seemed to be abbreviated here." )); + + // lower: max-1 to max+1, upper: min-1 + assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, -1, "" )); + assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, -1, "")); + assertEquals("One...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, -1, "...We are indeed close.")); + + // lower: max-1 to max+1, upper: min + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, 0, "" )); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, 0, "")); + assertEquals("...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, 0, "...We are indeed close.")); + + // lower: max-1 to max+1, upper: typical + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, 20, "" )); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, 20, "")); + assertEquals("One...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, 20, "...We are indeed close.")); + + // lower: max-1 to max+1, upper: max-1 + assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, Integer.MAX_VALUE-1, "" )); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, Integer.MAX_VALUE-1, "")); + assertEquals("One...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, Integer.MAX_VALUE-1, "...We are indeed close.")); + + // lower: max-1 to max+1, upper: max + assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, Integer.MAX_VALUE, "" )); + assertEquals("One day work will end, play is forever! One day play will end, work is forever!",WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, Integer.MAX_VALUE, "")); + assertEquals("One...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, Integer.MAX_VALUE, "...We are indeed close.")); + + // lower: max-1 to max+1, upper: max+1 + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, Integer.MAX_VALUE+1, "" )); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, Integer.MAX_VALUE+1, "")); + assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, Integer.MAX_VALUE+1, "...We are indeed close.")); + } + + + + } From 5f7d2edb57915fd06e05b1cbebe6308d9ec872d8 Mon Sep 17 00:00:00 2001 From: Alexander Leali Date: Sat, 19 Apr 2025 16:11:54 -0400 Subject: [PATCH 6/9] seperated the boundary testing assertions into test functions by different ranges --- .../commons/text/myWordsUtilsTests.java | 89 +++++++++++++------ 1 file changed, 63 insertions(+), 26 deletions(-) diff --git a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java index e2904e1678..c8ae4eebf8 100644 --- a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java +++ b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java @@ -84,92 +84,129 @@ public void delimiterCapitalizeTestWithVowelDelimiters(){ } } + //robust worst case boundary testing + + // lower: min to min+1, upper: min-1 @Test - public void abreviateTest(){ - //robust worst case boundary testing - // lower: min to min+1, upper: min-1 + public void abbreviateTestLowestExtremeBounds(){ + assertEquals("One... I'll find some way to end this.", WordUtils.abbreviate(sentenceForAbreviation, -1, -1, "... I'll find some way to end this." )); assertEquals("One...You will relive every key mistake you've ever made in your life.", WordUtils.abbreviate(sentenceForAbreviation, 0, -1, "...You will relive every key mistake you've ever made in your life.")); assertEquals("One...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, 1, -1, "...We are indeed close.")); + } - // lower: min-1 to min+1, upper: min + // lower: min-1 to min+1, upper: min + @Test + public void abbrevateTestLowestBounds(){ assertEquals("...Where did the sentence go?", WordUtils.abbreviate(sentenceForAbreviation, -1, 0, "...Where did the sentence go?" )); assertEquals("...There's nothing there.", WordUtils.abbreviate(sentenceForAbreviation, 0, 0, "...There's nothing there.")); assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 1, 0, "...Oops, that's an exception.")); + } - // lower: min-1 to min+1, upper: min+1 + // lower: min-1 to min+1, upper: min+1 + @Test + public void abbrevateTest2ndLowestBounds(){ assertEquals("O...Oh!", WordUtils.abbreviate(sentenceForAbreviation, -1, 1, "...Oh!" )); assertEquals("O, Oh...", WordUtils.abbreviate(sentenceForAbreviation, 0, 1, ", Oh...")); assertEquals("O...what about U?", WordUtils.abbreviate(sentenceForAbreviation, 1, 1, "...what about U?")); + } - // lower: min-1 to min+1, upper: typical + // lower: min-1 to min+1, upper: typical + @Test + public void abbrevateTestTypicalLowestBounds(){ assertEquals("One...huh?", WordUtils.abbreviate(sentenceForAbreviation, -1, 20, "...huh?" )); assertEquals("One...what?", WordUtils.abbreviate(sentenceForAbreviation, 0, 'Z', "...what?")); assertEquals("One...why?", WordUtils.abbreviate(sentenceForAbreviation, 1, 'z', "...why?")); + } - // lower: min-1 to min+1, upper: max-1 + // lower: min-1 to min+1, upper: max-1 + @Test + public void abbrevateTestLowestWith2ndHighest(){ assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, -1, Integer.MAX_VALUE-1, "" )); assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, 0, Integer.MAX_VALUE-1, "")); assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, 1, Integer.MAX_VALUE-1, "")); + } - // lower: min-1 to min+1, upper: max + // lower: min-1 to min+1, upper: max + @Test + public void abbrevateTestLowestWithHighest(){ assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, -1, Integer.MAX_VALUE, "" )); assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, 0, Integer.MAX_VALUE, "")); assertEquals("One", WordUtils.abbreviate(sentenceForAbreviation, 1, Integer.MAX_VALUE, "")); + } - // lower: min-1 to min+1, upper: max+1 - assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, -1, Integer.MAX_VALUE+1, "" )); - assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 0, Integer.MAX_VALUE+1, "")); - assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 1, Integer.MAX_VALUE+1, "")); - - // lower: typical, upper: min-1 to min+1 + // lower: typical, upper: min-1 to min+1 + @Test + public void abbrevateTestTypicalWithLowest(){ assertEquals("One day work will end, play is forever!... I'll find some way to end this.", WordUtils.abbreviate(sentenceForAbreviation, '!', -1, "... I'll find some way to end this." )); assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 'A', 0, "#-%" )); assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 'a', 1, "Nothing seemed to be abbreviated here." )); + } - // lower: typical, upper: typical - assertEquals("One day work will end, play is forever! One day play will end, work#-%", WordUtils.abbreviate(sentenceForAbreviation, 'A', 'Z', "#-%" )); + // lower: typical, upper: typical + @Test + public void abbrevateTestTypical(){ assertEquals("One day work will end, play is forever! One day play will end, work#-%", WordUtils.abbreviate(sentenceForAbreviation, 'A', 'Z', "#-%" )); } - // lower: typical, upper: max-1 to max+1 + // lower: typical, upper: max-1 to max+1 + @Test + public void abbrevateTestTypicalwithHighest(){ assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, 'a', Integer.MAX_VALUE-1, " Nothing seemed to be abbreviated here." )); assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, 'a', Integer.MAX_VALUE, " Nothing seemed to be abbreviated here." )); assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, 'a', Integer.MAX_VALUE+1, "Nothing seemed to be abbreviated here." )); + } + + // lower: max-1 to max+1, upper: min-1 + @Test + public void abbrevateTestMaximumWithLowestExtreme(){ - // lower: max-1 to max+1, upper: min-1 assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, -1, "" )); assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, -1, "")); assertEquals("One...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, -1, "...We are indeed close.")); + } + + // lower: max-1 to max+1, upper: min + @Test + public void abbrevateTestMaximumWithLowest(){ - // lower: max-1 to max+1, upper: min assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, 0, "" )); assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, 0, "")); assertEquals("...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, 0, "...We are indeed close.")); + } - // lower: max-1 to max+1, upper: typical + // lower: max-1 to max+1, upper: typical + @Test + public void abbrevateTestHighestWithTypical(){ assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, 20, "" )); assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, 20, "")); assertEquals("One...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, 20, "...We are indeed close.")); + } - // lower: max-1 to max+1, upper: max-1 + // lower: max-1 to max+1, upper: max-1 + @Test + public void abbrevateTest2ndHighestBounds(){ assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, Integer.MAX_VALUE-1, "" )); assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, Integer.MAX_VALUE-1, "")); assertEquals("One...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, Integer.MAX_VALUE-1, "...We are indeed close.")); + } - // lower: max-1 to max+1, upper: max + // lower: max-1 to max+1, upper: max + @Test + public void abbrevateTestHighestBounds(){ assertEquals("One day work will end, play is forever! One day play will end, work is forever!", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, Integer.MAX_VALUE, "" )); assertEquals("One day work will end, play is forever! One day play will end, work is forever!",WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, Integer.MAX_VALUE, "")); assertEquals("One...We are indeed close.", WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, Integer.MAX_VALUE, "...We are indeed close.")); + } - // lower: max-1 to max+1, upper: max+1 + // lower: max-1 to max+1, upper: max+1 + @Test + public void abbreviateTestHighestExtremeBounds(){ assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE-1, Integer.MAX_VALUE+1, "" )); assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE, Integer.MAX_VALUE+1, "")); assertThrows(IllegalArgumentException.class, () -> WordUtils.abbreviate(sentenceForAbreviation, Integer.MAX_VALUE+1, Integer.MAX_VALUE+1, "...We are indeed close.")); - - } - + From 9e1614115ac91d09a49cbb4edff8284a5ae46683 Mon Sep 17 00:00:00 2001 From: Alexander Leali Date: Sun, 20 Apr 2025 17:54:40 -0400 Subject: [PATCH 7/9] added a partition equivalence testing for the containsAllWords method --- .../commons/text/myWordsUtilsTests.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java index c8ae4eebf8..d476dc5651 100644 --- a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java +++ b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java @@ -43,6 +43,9 @@ public class myWordsUtilsTests { private static String sentenceForAbreviation; + private static String[] setencesForContainsAllWords; + private static String[] wordsToFind; + @BeforeAll public static void setUp(){ typicalSentence = "The quick brown fox jumps over the lazy dog"; @@ -54,6 +57,8 @@ public static void setUp(){ expectedDelimitedSentences = new String[]{"!The @quick #brown $fox %jumps ^over &the *lazy (dog", "!the @Quick #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #Brown $fox %jumps ^over &the *lazy (dog", "!the @quick #brown $Fox %jumps ^over &the *lazy (dog", "!the @quick #brown $fox %Jumps ^over &the *lazy (dog", "!the @quick #brown $fox %jumps ^Over &the *lazy (dog", "!the @quick #brown $fox %jumps ^over &The *lazy (dog", "!the @quick #brown $fox %jumps ^over &the *Lazy (dog", "!the @quick #brown $fox %jumps ^over &the *lazy (Dog"}; expectedVoweledSentences = new String[]{"!the @quick #brown $fox %jumps ^over &the *laZy (dog", "!the @quick #brown $fox %jumps ^oveR &the *lazy (dog", "!the @quiCk #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #broWn $foX %jumps ^oVer &the *lazy (doG", "!the @quIck #brown $fox %juMps ^over &the *lazy (dog"}; sentenceForAbreviation = "One day work will end, play is forever! One day play will end, work is forever!"; + setencesForContainsAllWords = new String[] {"\"\"", "\"Writing\" tests to ensure code is working properly", "Writing tests to ensure code is \\working\\ properly", "\'", "Writing tests to ensure code is working properly", "03 1985", "!@# $%^ ^&*"}; + } //partiton testing @@ -206,6 +211,51 @@ public void abbreviateTestHighestExtremeBounds(){ } + //partiton testing + @Test + public void containsAllWordsTestQuoteEscape(){ + assertEquals(false, WordUtils.containsAllWords(setencesForContainsAllWords[0], "\"","\"")); + } + + @Test + public void containsAllWordsTestSentenceAndQuotes(){ + assertEquals(false, WordUtils.containsAllWords(setencesForContainsAllWords[1], "\"Writing\"", "tests", "to", "ensure", "code", "is", "working", "lazy", "properly")); + } + + @Test + public void containsAllWordsTestNotScaningAll(){ + assertEquals(false, WordUtils.containsAllWords(setencesForContainsAllWords[2], "tests", "code", "\\working\\")); + + } + + @Test + public void containsAllWordsTestEscapeApostrophe(){ + assertEquals(false, WordUtils.containsAllWords(setencesForContainsAllWords[3], "\'")); + } + + @Test + public void containsAllWordsTypical(){ + assertEquals(true, WordUtils.containsAllWords(setencesForContainsAllWords[4], "Writing", "tests", "to", "ensure", "code", "is", "working", "properly")); + } + + @Test + public void containsAllWordsNumbers(){ + assertEquals(true, WordUtils.containsAllWords(setencesForContainsAllWords[5], "03", "1985")); + + } + + @Test + public void containsAllWordsSymbols(){ + assertEquals(false, WordUtils.containsAllWords(setencesForContainsAllWords[6], "!@#", "$%^", "^&*")); + + } + + + + + + + From 4487de669e9a3920c166486526da2cba721e06c8 Mon Sep 17 00:00:00 2001 From: Alexander Leali Date: Sun, 20 Apr 2025 18:35:23 -0400 Subject: [PATCH 8/9] added partition testing to the swapCase method --- .../commons/text/myWordsUtilsTests.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java index d476dc5651..5513c835b7 100644 --- a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java +++ b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java @@ -44,7 +44,8 @@ public class myWordsUtilsTests { private static String sentenceForAbreviation; private static String[] setencesForContainsAllWords; - private static String[] wordsToFind; + private static String[] sentencesForSwapCase; + private static String accentedVowels; @BeforeAll public static void setUp(){ @@ -58,6 +59,8 @@ public static void setUp(){ expectedVoweledSentences = new String[]{"!the @quick #brown $fox %jumps ^over &the *laZy (dog", "!the @quick #brown $fox %jumps ^oveR &the *lazy (dog", "!the @quiCk #brown $fox %jumps ^over &the *lazy (dog", "!the @quick #broWn $foX %jumps ^oVer &the *lazy (doG", "!the @quIck #brown $fox %juMps ^over &the *lazy (dog"}; sentenceForAbreviation = "One day work will end, play is forever! One day play will end, work is forever!"; setencesForContainsAllWords = new String[] {"\"\"", "\"Writing\" tests to ensure code is working properly", "Writing tests to ensure code is \\working\\ properly", "\'", "Writing tests to ensure code is working properly", "03 1985", "!@# $%^ ^&*"}; + sentencesForSwapCase = new String[] {"\bWriting\btests\bto\bensure\bcode\bis\bworking\bproperly", "Writing tests to ensure code is working properly", "20 09 1555"}; + accentedVowels = "αινσϊ"; } @@ -250,6 +253,33 @@ public void containsAllWordsSymbols(){ } + @Test + public void swapCaseTestSymbols(){ + assertEquals(delimiters, WordUtils.swapCase(delimiters)); + } + + @Test + public void swapCaseTestEscapeSequencesInSentence(){ + assertEquals("\bwRITING\bTESTS\bTO\bENSURE\bCODE\bIS\bWORKING\bPROPERLY", WordUtils.swapCase(sentencesForSwapCase[0])); + } + + @Test + public void swapCaseTestTypical(){ + assertEquals("wRITING TESTS TO ENSURE CODE IS WORKING PROPERLY", WordUtils.swapCase(sentencesForSwapCase[1])); + } + + @Test + public void swapCaseTestNumbers(){ + assertEquals(sentencesForSwapCase[2], WordUtils.swapCase(sentencesForSwapCase[2])); + } + + @Test + public void swapCaseTestAccentedVowels(){ + assertEquals("ΑΙΝΣΪ", WordUtils.swapCase(accentedVowels)); + } + + + From 17ed52fb84c18cd480b6fee864702b0658c3194c Mon Sep 17 00:00:00 2001 From: Alexander Leali Date: Sun, 20 Apr 2025 20:03:30 -0400 Subject: [PATCH 9/9] tested the initals method with partition equivalence --- .../commons/text/myWordsUtilsTests.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java index 5513c835b7..fdb34209dc 100644 --- a/src/test/java/org/apache/commons/text/myWordsUtilsTests.java +++ b/src/test/java/org/apache/commons/text/myWordsUtilsTests.java @@ -47,6 +47,8 @@ public class myWordsUtilsTests { private static String[] sentencesForSwapCase; private static String accentedVowels; + private static String[] sentencesForInitals; + @BeforeAll public static void setUp(){ typicalSentence = "The quick brown fox jumps over the lazy dog"; @@ -61,6 +63,7 @@ public static void setUp(){ setencesForContainsAllWords = new String[] {"\"\"", "\"Writing\" tests to ensure code is working properly", "Writing tests to ensure code is \\working\\ properly", "\'", "Writing tests to ensure code is working properly", "03 1985", "!@# $%^ ^&*"}; sentencesForSwapCase = new String[] {"\bWriting\btests\bto\bensure\bcode\bis\bworking\bproperly", "Writing tests to ensure code is working properly", "20 09 1555"}; accentedVowels = "αινσϊ"; + sentencesForInitals = new String[]{"\b\n\t","\b \n \t", "&^%", "& ^ %", "[|]", "[ | ]", "\b[\n|\t]", "I'm gonna go grab some coffee.", "03 03 2023"}; } @@ -278,6 +281,33 @@ public void swapCaseTestAccentedVowels(){ assertEquals("ΑΙΝΣΪ", WordUtils.swapCase(accentedVowels)); } + @Test + public void initalsTestEscapeCharacters(){ assertEquals("\b", WordUtils.initials(sentencesForInitals[0])); } + + @Test + public void initalsTestEscapeCharactersSpaces(){ assertEquals("\b", WordUtils.initials(sentencesForInitals[1])); } + + @Test + public void initalsTestSymbols(){ assertEquals("&", WordUtils.initials(sentencesForInitals[2])); } + + @Test + public void initalsTestSymbolsSpaces(){ assertEquals("&^%", WordUtils.initials(sentencesForInitals[3])); } + + @Test + public void initalsTestBracketLine(){ assertEquals("[", WordUtils.initials(sentencesForInitals[4])); } + + @Test + public void initalsTestBracketLineSpaces(){ assertEquals("[|]", WordUtils.initials(sentencesForInitals[5])); } + + @Test + public void initalsTestCombinationOfLastThree(){ assertEquals("\b|]", WordUtils.initials(sentencesForInitals[6])); } + + @Test + public void initalsTestTypical(){ assertEquals("Igggsc", WordUtils.initials(sentencesForInitals[7])); } + + @Test + public void initalsTestNumbers(){ assertEquals("002", WordUtils.initials(sentencesForInitals[8])); } +