Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/test/java/org/apache/commons/text/CapitalizeTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}

Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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"));
}
}