mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
fix: change location of others to correct places (#5559)
This commit is contained in:
24
src/test/java/com/thealgorithms/strings/CountCharTest.java
Normal file
24
src/test/java/com/thealgorithms/strings/CountCharTest.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
class CountCharTest {
|
||||
|
||||
@ParameterizedTest(name = "\"{0}\" should have {1} non-whitespace characters")
|
||||
@CsvSource({"'', 0", "' ', 0", "'a', 1", "'abc', 3", "'a b c', 3", "' a b c ', 3", "'\tabc\n', 3", "' a b\tc ', 3", "' 12345 ', 5", "'Hello, World!', 12"})
|
||||
@DisplayName("Test countCharacters with various inputs")
|
||||
void testCountCharacters(String input, int expected) {
|
||||
assertEquals(expected, CountChar.countCharacters(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test countCharacters with null input")
|
||||
void testCountCharactersNullInput() {
|
||||
assertEquals(0, CountChar.countCharacters(null));
|
||||
}
|
||||
}
|
||||
31
src/test/java/com/thealgorithms/strings/CountWordsTest.java
Normal file
31
src/test/java/com/thealgorithms/strings/CountWordsTest.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
class CountWordsTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("wordCountTestCases")
|
||||
void testWordCount(String input, int expectedCount) {
|
||||
assertEquals(expectedCount, CountWords.wordCount(input));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("secondaryWordCountTestCases")
|
||||
void testSecondaryWordCount(String input, int expectedCount) {
|
||||
assertEquals(expectedCount, CountWords.secondaryWordCount(input));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> wordCountTestCases() {
|
||||
return Stream.of(Arguments.of("", 0), Arguments.of(null, 0), Arguments.of("aaaa bbb cccc", 3), Arguments.of("note extra spaces here", 4), Arguments.of(" a b c d e ", 5));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> secondaryWordCountTestCases() {
|
||||
return Stream.of(Arguments.of("", 0), Arguments.of(null, 0), Arguments.of("aaaa bbb cccc", 3), Arguments.of("this-is-one-word!", 1), Arguments.of("What, about, this? Hmmm----strange", 4), Arguments.of("word1 word-2 word-3- w?o,r.d.@!@#$&*()<>4", 4));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
class ReturnSubsequenceTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCases")
|
||||
void testSubsequences(String input, String[] expected) {
|
||||
String[] actual = ReturnSubsequence.getSubsequences(input);
|
||||
assertArrayEquals(expected, actual);
|
||||
}
|
||||
|
||||
static Stream<Arguments> provideTestCases() {
|
||||
return Stream.of(Arguments.of("", new String[] {""}), Arguments.of("a", new String[] {"", "a"}), Arguments.of("ab", new String[] {"", "b", "a", "ab"}), Arguments.of("abc", new String[] {"", "c", "b", "bc", "a", "ac", "ab", "abc"}),
|
||||
Arguments.of("aab", new String[] {"", "b", "a", "ab", "a", "ab", "aa", "aab"}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
class StringMatchFiniteAutomataTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCases")
|
||||
void searchPattern(String text, String pattern, Set<Integer> expectedOutput) {
|
||||
assertEquals(expectedOutput, StringMatchFiniteAutomata.searchPattern(text, pattern));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> provideTestCases() {
|
||||
return Stream.of(Arguments.of("abcbcabc", "abc", Set.of(0, 5)), Arguments.of("", "abc", Set.of()), Arguments.of("", "", Set.of()), Arguments.of("a", "b", Set.of()), Arguments.of("a", "a", Set.of(0)), Arguments.of("abcdabcabcabcd", "abcd", Set.of(0, 10)), Arguments.of("abc", "bcd", Set.of()),
|
||||
Arguments.of("abcdefg", "xyz", Set.of()), Arguments.of("abcde", "", Set.of(1, 2, 3, 4, 5)), Arguments.of("abcabcabc", "abc", Set.of(0, 3, 6)), Arguments.of("abcabcabc", "abcabcabc", Set.of(0)), Arguments.of("aaabbbaaa", "aaa", Set.of(0, 6)), Arguments.of("abcdefg", "efg", Set.of(4)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user