From c8432c69c0408b6e0abd4f3874431f969b129874 Mon Sep 17 00:00:00 2001 From: Nicklavi11 Date: Thu, 10 Apr 2025 20:08:21 -0400 Subject: [PATCH 1/4] Added Equivalence Partitioning test for WordUtils.java --- .../apache/commons/text/CapitalizeTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/test/java/org/apache/commons/text/CapitalizeTest.java diff --git a/src/test/java/org/apache/commons/text/CapitalizeTest.java b/src/test/java/org/apache/commons/text/CapitalizeTest.java new file mode 100644 index 0000000000..4ddba02228 --- /dev/null +++ b/src/test/java/org/apache/commons/text/CapitalizeTest.java @@ -0,0 +1,72 @@ +/* + * 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 + * + * https://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 org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class CapitalizeTest { + // Equivalence Partition Case 1: Empty String + @Test + void testEmptyString() { + assertEquals("", WordUtils.capitalize("")); + } + + // Equivalence Partition Case 2: Single lowercase word + @Test + void testSingleLowercaseWord() { + assertEquals("Hello", WordUtils.capitalize("hello")); + } + + // Equivalence Partition Case 3: Single all uppercase word + @Test + void testSingleUppercaseWord() { + assertEquals("HELLO", WordUtils.capitalize("HELLO")); + } + + // Equivalence Partition Case 4: Multiple lowercase words + @Test + void testMultipleLowercaseWords() { + assertEquals("Hello World", WordUtils.capitalize("hello world")); + } + + // Equivalence Partition Case 5: Whitespace around words + @Test + void testWhitespaceAroundWord() { + assertEquals(" Hello World ", WordUtils.capitalize(" hello world ")); + } + + // Equivalence Partition Case 6: Mixed uppercase and lowercase words + @Test + void testMixedWord() { + assertEquals("HELlO WOrLd", WordUtils.capitalize("hELlO wOrLd")); + } + + // Equivalence Partition Case 7: Word with number + @Test + void testNumberWithWord() { + assertEquals("Hello 123", WordUtils.capitalize("hello 123")); + } + + // Equivalence Partition Case 8: Null input + @Test + void testNullWord() { + assertNull(WordUtils.capitalize(null)); + } +} + From e1e81d5aaf97e05b8e92828f4bba69a97b1fd9ae Mon Sep 17 00:00:00 2001 From: Nicklavi11 Date: Fri, 11 Apr 2025 10:49:02 -0400 Subject: [PATCH 2/4] Added JUnit test for RandomStringGenerator.java --- .../text/RandomStringGenerateTest.java | 37 +++++++++++++++++++ .../JaroWinklerDistanceScoreTest.java | 4 ++ 2 files changed, 41 insertions(+) create mode 100644 src/test/java/org/apache/commons/text/RandomStringGenerateTest.java create mode 100644 src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceScoreTest.java diff --git a/src/test/java/org/apache/commons/text/RandomStringGenerateTest.java b/src/test/java/org/apache/commons/text/RandomStringGenerateTest.java new file mode 100644 index 0000000000..17c4b53e31 --- /dev/null +++ b/src/test/java/org/apache/commons/text/RandomStringGenerateTest.java @@ -0,0 +1,37 @@ +/* + * 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 + * + * https://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 org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class RandomStringGenerateTest { + + @Test + void returnStringWithinRange() { + // Setup: Creates a random string generator with the character ranges + RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange('a', 'z').build(); + + // Test: Generates a random stings and provides the requested range + String random = generator.generate(10); + + // Verify: makes sure it is not null and checks the length of the generated string. If the length is 10 then it passes + assertNotNull(random); + assertEquals(10, random.length()); + } +} diff --git a/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceScoreTest.java b/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceScoreTest.java new file mode 100644 index 0000000000..829243406e --- /dev/null +++ b/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceScoreTest.java @@ -0,0 +1,4 @@ +package org.apache.commons.text.similarity; + +public class JaroWinklerDistanceScoreTest { +} From 51ac1e874a2b972c46e29aac0bcd47d89b56c047 Mon Sep 17 00:00:00 2001 From: Nicklavi11 Date: Fri, 11 Apr 2025 12:55:18 -0400 Subject: [PATCH 3/4] Added boundary test for JaroWinklerDistance.java --- .../JaroWinklerDistanceScoreTest.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceScoreTest.java b/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceScoreTest.java index 829243406e..f78ae8515d 100644 --- a/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceScoreTest.java +++ b/src/test/java/org/apache/commons/text/similarity/JaroWinklerDistanceScoreTest.java @@ -1,4 +1,66 @@ +/* + * 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.similarity; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + public class JaroWinklerDistanceScoreTest { + + private static JaroWinklerDistance distance; + + @BeforeAll + public static void setUp() { + distance = new JaroWinklerDistance(); + } + + //min: looking for a 0.0 + @Test + void perfectMatchTest() { + assertEquals(0.0, distance.apply("hello", "hello")); + } + + //min+1: looking for a value greater than 0.0 but less than 0.1 + @Test + void slightlyPerfectMatchTest() { + double actual = distance.apply("hello", "hello!"); + assertTrue(actual > 0.0 && actual < 0.1); + } + + //typical: looking for a value greater than 0.1 and less than 0.5 + @Test + void mediumMatchTest() { + double actual = distance.apply("hello", "help"); + assertTrue(actual > 0.1 && actual < 0.5); + } + + //max-1: looking for a value greater than 0.5 and less than 1.0 + @Test + void slightlyCompletelyDifferentMatchTest() { + double actual = distance.apply("hello", "world"); + assertTrue(actual > 0.5 && actual < 1.0); + + } + + //max: looking for a 1.0 + @Test + void completeDifferentMatchTest() { + assertEquals(1.0, distance.apply("hello", "nope")); + } } From d6717b1ab6c3fc9146c95abd9aa5c17a0f4df01f Mon Sep 17 00:00:00 2001 From: Nicklavi11 Date: Wed, 23 Apr 2025 12:32:06 -0400 Subject: [PATCH 4/4] Added TopDown Test for StringEscapeUtils.java --- .../text/StringEscapeUtilsTopDownTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/java/org/apache/commons/text/StringEscapeUtilsTopDownTest.java diff --git a/src/test/java/org/apache/commons/text/StringEscapeUtilsTopDownTest.java b/src/test/java/org/apache/commons/text/StringEscapeUtilsTopDownTest.java new file mode 100644 index 0000000000..7c23338523 --- /dev/null +++ b/src/test/java/org/apache/commons/text/StringEscapeUtilsTopDownTest.java @@ -0,0 +1,39 @@ +/* + * 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 + * + * https://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 org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class StringEscapeUtilsTopDownTest { + + @Test + void shouldEscapeJavaSpecialCharacters() { + // Setup: A string with special characters (double quote) + String input = "He said, \"Hello\""; + + // Expected: the output should have escaped double quotes + String expected = "He said, \\\"Hello\\\""; + + // Act: use StringEscapeUtils to escape the Java string + String actual = StringEscapeUtils.escapeJava(input); + + // Verify: check that the escaped output matches what we expect + assertEquals(expected, actual); + } +}