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:
@@ -1,30 +0,0 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
public final class ArrayRightRotation {
|
||||
private ArrayRightRotation() {
|
||||
}
|
||||
public static int[] rotateRight(int[] arr, int k) {
|
||||
if (arr == null || arr.length == 0 || k < 0) {
|
||||
throw new IllegalArgumentException("Invalid input");
|
||||
}
|
||||
|
||||
int n = arr.length;
|
||||
k = k % n; // Handle cases where k is larger than the array length
|
||||
|
||||
reverseArray(arr, 0, n - 1);
|
||||
reverseArray(arr, 0, k - 1);
|
||||
reverseArray(arr, k, n - 1);
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
private static void reverseArray(int[] arr, int start, int end) {
|
||||
while (start < end) {
|
||||
int temp = arr[start];
|
||||
arr[start] = arr[end];
|
||||
arr[end] = temp;
|
||||
start++;
|
||||
end--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CountSetBitsTest {
|
||||
|
||||
@Test
|
||||
void testSetBits() {
|
||||
CountSetBits csb = new CountSetBits();
|
||||
assertEquals(1L, csb.countSetBits(16));
|
||||
assertEquals(4, csb.countSetBits(15));
|
||||
assertEquals(5, csb.countSetBits(10000));
|
||||
assertEquals(5, csb.countSetBits(31));
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
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"}));
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
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