Skip to content

Commit

Permalink
tune method name in delimiter algorithm unit test
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <[email protected]>
  • Loading branch information
yuye-aws committed Mar 15, 2024
1 parent 3f41f37 commit e4bdabc
Showing 1 changed file with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class DelimiterChunkerTests extends OpenSearchTestCase {

public void testChunkerWithDelimiterFieldNotString() {
public void testCreate_withDelimiterFieldInvalidType_thenFail() {
Exception exception = assertThrows(
IllegalArgumentException.class,
() -> new DelimiterChunker(Map.of(DELIMITER_FIELD, List.of("")))
Expand All @@ -26,55 +26,48 @@ public void testChunkerWithDelimiterFieldNotString() {
);
}

public void testChunkerWithDelimiterFieldNoString() {
public void testCreate_withDelimiterFieldEmptyString_thenFail() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new DelimiterChunker(Map.of(DELIMITER_FIELD, "")));
Assert.assertEquals(String.format(Locale.ROOT, "Parameter [%s] should not be empty.", DELIMITER_FIELD), exception.getMessage());
}

public void testChunker() {
public void testChunk_withNewlineDelimiter_thenSucceed() {
DelimiterChunker chunker = new DelimiterChunker(Map.of(DELIMITER_FIELD, "\n"));
String content = "a\nb\nc\nd";
List<String> chunkResult = chunker.chunk(content, Map.of());
assertEquals(List.of("a\n", "b\n", "c\n", "d"), chunkResult);
}

public void testChunkerWithDefaultDelimiter() {
public void testChunk_withDefaultDelimiter_thenSucceed() {
// default delimiter is \n\n
DelimiterChunker chunker = new DelimiterChunker(Map.of());
String content = "a.b\n\nc.d";
List<String> chunkResult = chunker.chunk(content, Map.of());
assertEquals(List.of("a.b\n\n", "c.d"), chunkResult);
}

public void testChunkerWithDelimiterEnd() {
DelimiterChunker chunker = new DelimiterChunker(Map.of(DELIMITER_FIELD, "\n"));
String content = "a\nb\nc\nd\n";
List<String> chunkResult = chunker.chunk(content, Map.of());
assertEquals(List.of("a\n", "b\n", "c\n", "d\n"), chunkResult);
}

public void testChunkerWithOnlyDelimiter() {
public void testChunk_withOnlyDelimiterContent_thenSucceed() {
DelimiterChunker chunker = new DelimiterChunker(Map.of(DELIMITER_FIELD, "\n"));
String content = "\n";
List<String> chunkResult = chunker.chunk(content, Map.of());
assertEquals(List.of("\n"), chunkResult);
}

public void testChunkerWithAllDelimiters() {
public void testChunk_WithAllDelimiterContent_thenSucceed() {
DelimiterChunker chunker = new DelimiterChunker(Map.of(DELIMITER_FIELD, "\n"));
String content = "\n\n\n";
List<String> chunkResult = chunker.chunk(content, Map.of());
assertEquals(List.of("\n", "\n", "\n"), chunkResult);
}

public void testChunkerWithDifferentDelimiters() {
public void testChunk_WithPeriodDelimiters_thenSucceed() {
DelimiterChunker chunker = new DelimiterChunker(Map.of(DELIMITER_FIELD, "."));
String content = "a.b.cc.d.";
List<String> chunkResult = chunker.chunk(content, Map.of());
assertEquals(List.of("a.", "b.", "cc.", "d."), chunkResult);
}

public void testChunkerWithStringDelimiter() {
public void testChunk_withDoubleNewlineDelimiter_thenSucceed() {
DelimiterChunker chunker = new DelimiterChunker(Map.of(DELIMITER_FIELD, "\n\n"));
String content = "\n\na\n\n\n";
List<String> chunkResult = chunker.chunk(content, Map.of());
Expand Down

0 comments on commit e4bdabc

Please sign in to comment.