Skip to content

Commit

Permalink
Merge pull request #4 from xinyual/addMoreUTForDelimiterChunker
Browse files Browse the repository at this point in the history
add more UTs and logic to check whether input is empty
  • Loading branch information
xinyual authored Feb 27, 2024
2 parents e104e1b + 73ff44b commit 51905df
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public void validateParameters(Map<String, Object> parameters) {
if (parameters.containsKey(DELIMITER_FIELD)) {
Object delimiter = parameters.get(DELIMITER_FIELD);
if (!(delimiter instanceof String)) {
throw new IllegalArgumentException("delimiter parameters: " + delimiter + " must be string");
throw new IllegalArgumentException("delimiter parameters: " + delimiter + " must be string.");
} else if (((String) delimiter).length() == 0) {
throw new IllegalArgumentException("delimiter parameters should not be empty.");
}
} else {
throw new IllegalArgumentException("You must contain field:" + DELIMITER_FIELD + " in your parameter");
throw new IllegalArgumentException("You must contain field:" + DELIMITER_FIELD + " in your parameter.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
package org.opensearch.neuralsearch.processor;public class DocumentChunkingProcessorTests {
}
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
package org.opensearch.neuralsearch.processor;

public class DocumentChunkingProcessorTests {}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void testChunkerWithNoDelimiterField() {
String content = "a\nb\nc\nd";
Map<String, Object> inputParameters = Map.of("", "");
Exception exception = assertThrows(IllegalArgumentException.class, () -> chunker.validateParameters(inputParameters));
Assert.assertEquals("You must contain field:" + DELIMITER_FIELD + " in your parameter", exception.getMessage());
Assert.assertEquals("You must contain field:" + DELIMITER_FIELD + " in your parameter.", exception.getMessage());
}

@Test
Expand All @@ -31,7 +31,16 @@ public void testChunkerWithDelimiterFieldNotString() {
String content = "a\nb\nc\nd";
Map<String, Object> inputParameters = Map.of(DELIMITER_FIELD, List.of(""));
Exception exception = assertThrows(IllegalArgumentException.class, () -> chunker.validateParameters(inputParameters));
Assert.assertEquals("delimiter parameters: " + List.of("") + " must be string", exception.getMessage());
Assert.assertEquals("delimiter parameters: " + List.of("") + " must be string.", exception.getMessage());
}

@Test
public void testChunkerWithDelimiterFieldNoString() {
DelimiterChunker chunker = new DelimiterChunker();
String content = "a\nb\nc\nd";
Map<String, Object> inputParameters = Map.of(DELIMITER_FIELD, "");
Exception exception = assertThrows(IllegalArgumentException.class, () -> chunker.validateParameters(inputParameters));
Assert.assertEquals("delimiter parameters should not be empty.", exception.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
}
}
]
}
}

0 comments on commit 51905df

Please sign in to comment.