89 lines
3.3 KiB
Java
89 lines
3.3 KiB
Java
package ai.nomyo;
|
|
|
|
import ai.nomyo.util.Splitter;
|
|
import org.junit.jupiter.api.*;
|
|
|
|
import java.util.List;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
|
class SplitterTest {
|
|
|
|
@Test
|
|
@DisplayName("fixedLengthString should split string into equal parts")
|
|
void fixedLengthString_equalParts_shouldSplitCorrectly() {
|
|
List<String> result = Splitter.fixedLengthString(5, "1234567890");
|
|
|
|
assertEquals(2, result.size(), "Should have 2 parts");
|
|
assertEquals("12345", result.get(0), "First part should be '12345'");
|
|
assertEquals("67890", result.get(1), "Second part should be '67890'");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("fixedLengthString should handle last part being shorter")
|
|
void fixedLengthString_lastPartShorter_shouldWork() {
|
|
List<String> result = Splitter.fixedLengthString(5, "123456789");
|
|
|
|
assertEquals(2, result.size(), "Should have 2 parts");
|
|
assertEquals("12345", result.get(0), "First part should be '12345'");
|
|
assertEquals("6789", result.get(1), "Second part should be '6789'");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("fixedLengthString with length equal to string should return single part")
|
|
void fixedLengthString_lengthEqualsString_shouldReturnSingle() {
|
|
List<String> result = Splitter.fixedLengthString(10, "1234567890");
|
|
|
|
assertEquals(1, result.size(), "Should have 1 part");
|
|
assertEquals("1234567890", result.get(0), "Single part should be the full string");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("fixedLengthString with length greater than string should return single part")
|
|
void fixedLengthString_lengthGreaterThanString_shouldReturnSingle() {
|
|
List<String> result = Splitter.fixedLengthString(100, "hello");
|
|
|
|
assertEquals(1, result.size(), "Should have 1 part");
|
|
assertEquals("hello", result.get(0), "Single part should be 'hello'");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("fixedLengthString with length 1 should split into single characters")
|
|
void fixedLengthString_lengthOne_shouldSplitChars() {
|
|
List<String> result = Splitter.fixedLengthString(1, "abc");
|
|
|
|
assertEquals(3, result.size(), "Should have 3 parts");
|
|
assertEquals("a", result.get(0));
|
|
assertEquals("b", result.get(1));
|
|
assertEquals("c", result.get(2));
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("fixedLengthString with empty string should return empty list")
|
|
void fixedLengthString_emptyString_shouldReturnEmpty() {
|
|
List<String> result = Splitter.fixedLengthString(5, "");
|
|
|
|
assertEquals(0, result.size(), "Should return empty list");
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("fixedLengthString should handle string with special characters")
|
|
void fixedLengthString_specialChars_shouldSplitCorrectly() {
|
|
List<String> result = Splitter.fixedLengthString(3, "a!@b#c$");
|
|
|
|
assertEquals(3, result.size(), "Should have 3 parts");
|
|
assertEquals("a!@", result.get(0));
|
|
assertEquals("b#c", result.get(1));
|
|
assertEquals("$", result.get(2));
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("fixedLengthString should handle unicode characters")
|
|
void fixedLengthString_unicode_shouldSplitCorrectly() {
|
|
List<String> result = Splitter.fixedLengthString(2, "ab\u00e9\u00fc");
|
|
|
|
assertEquals(2, result.size(), "Should have 2 parts");
|
|
assertEquals("ab", result.get(0));
|
|
}
|
|
}
|