-
Notifications
You must be signed in to change notification settings - Fork 2
feat: wire up JaCoCo coverage reporting and enforcement #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8eecf77
feat(GTI-847): wire up JaCoCo coverage reporting and enforcement
sagile f3661e4
fix(GTI-847): address Bugbot review findings
sagile eaa3cd5
fix: upload coverage reports even when verification gate fails
sagile a4954a7
fix: exclude no-logic classes from JaCoCo coverage gate
sagile dfeffe1
feat: lower coverage gate to 42% and add unit tests for pure-Java cla…
sagile 4634851
style: fix spotless formatting in UtilsTest
sagile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
core/src/test/java/com/redis/vl/extensions/summarization/EmbeddedSentenceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.redis.vl.extensions.summarization; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class EmbeddedSentenceTest { | ||
|
|
||
| @Test | ||
| void indexIsPreserved() { | ||
| EmbeddedSentence s = new EmbeddedSentence(3, new float[] {1.0f, 0.0f}); | ||
| assertThat(s.index()).isEqualTo(3); | ||
| } | ||
|
|
||
| @Test | ||
| void getPointReturnsSameDimensionality() { | ||
| float[] embedding = {1.0f, 2.0f, 3.0f}; | ||
| EmbeddedSentence s = new EmbeddedSentence(0, embedding); | ||
| assertThat(s.getPoint()).hasSize(3); | ||
| } | ||
|
|
||
| @Test | ||
| void cosineSimilarityOfIdenticalVectorsIsOne() { | ||
| float[] v = {1.0f, 0.0f, 0.0f}; | ||
| EmbeddedSentence a = new EmbeddedSentence(0, v); | ||
| EmbeddedSentence b = new EmbeddedSentence(1, v); | ||
| assertThat(a.cosineSimilarity(b)).isCloseTo(1.0, org.assertj.core.data.Offset.offset(0.001)); | ||
| } | ||
|
|
||
| @Test | ||
| void cosineSimilarityOfOrthogonalVectorsIsZero() { | ||
| EmbeddedSentence a = new EmbeddedSentence(0, new float[] {1.0f, 0.0f}); | ||
| EmbeddedSentence b = new EmbeddedSentence(1, new float[] {0.0f, 1.0f}); | ||
| assertThat(a.cosineSimilarity(b)).isCloseTo(0.0, org.assertj.core.data.Offset.offset(0.001)); | ||
| } | ||
|
|
||
| @Test | ||
| void cosineSimilarityOfOppositeVectorsIsMinusOne() { | ||
| EmbeddedSentence a = new EmbeddedSentence(0, new float[] {1.0f, 0.0f}); | ||
| EmbeddedSentence b = new EmbeddedSentence(1, new float[] {-1.0f, 0.0f}); | ||
| assertThat(a.cosineSimilarity(b)).isCloseTo(-1.0, org.assertj.core.data.Offset.offset(0.001)); | ||
| } | ||
|
|
||
| @Test | ||
| void cosineSimilarityOfZeroVectorIsZero() { | ||
| EmbeddedSentence a = new EmbeddedSentence(0, new float[] {1.0f, 0.0f}); | ||
| EmbeddedSentence zero = new EmbeddedSentence(1, new float[] {0.0f, 0.0f}); | ||
| assertThat(a.cosineSimilarity(zero)).isEqualTo(0.0); | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
core/src/test/java/com/redis/vl/extensions/summarization/SentenceSplitterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.redis.vl.extensions.summarization; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.util.List; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class SentenceSplitterTest { | ||
|
|
||
| private SentenceSplitter splitter; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| splitter = new SentenceSplitter(); | ||
| } | ||
|
|
||
| @Test | ||
| void splitSimpleSentences() { | ||
| List<String> result = splitter.split("Hello world. How are you? I am fine."); | ||
| assertThat(result).hasSize(3); | ||
| } | ||
|
|
||
| @Test | ||
| void splitReturnsEmptyListForNull() { | ||
| assertThat(splitter.split(null)).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void splitReturnsEmptyListForBlank() { | ||
| assertThat(splitter.split(" ")).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void splitSingleSentenceReturnsSingleElement() { | ||
| List<String> result = splitter.split("Just one sentence here."); | ||
| assertThat(result).hasSize(1); | ||
| assertThat(result.get(0)).isEqualTo("Just one sentence here."); | ||
| } | ||
|
|
||
| @Test | ||
| void splitWithSpansReturnsEmptyForNull() { | ||
| assertThat(splitter.splitWithSpans(null)).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void splitWithSpansReturnsEmptyForBlank() { | ||
| assertThat(splitter.splitWithSpans("")).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void splitWithSpansReturnsCorrectCount() { | ||
| var spans = splitter.splitWithSpans("First sentence. Second sentence."); | ||
| assertThat(spans).hasSize(2); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package com.redis.vl.utils; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ArrayUtilsTest { | ||
|
|
||
| @Test | ||
| void floatArrayToBytesAndBackRoundTrips() { | ||
| float[] original = {1.0f, 2.5f, -3.14f, 0.0f}; | ||
| byte[] bytes = ArrayUtils.floatArrayToBytes(original); | ||
| float[] result = ArrayUtils.bytesToFloatArray(bytes); | ||
| assertThat(result).hasSize(original.length); | ||
| for (int i = 0; i < original.length; i++) { | ||
| assertThat(result[i]).isCloseTo(original[i], org.assertj.core.data.Offset.offset(0.001f)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void floatArrayToBytesNullReturnsNull() { | ||
| assertThat(ArrayUtils.floatArrayToBytes(null)).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void bytesToFloatArrayNullReturnsNull() { | ||
| assertThat(ArrayUtils.bytesToFloatArray(null)).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void floatArrayToBytesProducesCorrectLength() { | ||
| float[] floats = {1.0f, 2.0f, 3.0f}; | ||
| byte[] bytes = ArrayUtils.floatArrayToBytes(floats); | ||
| assertThat(bytes).hasSize(floats.length * Float.BYTES); | ||
| } | ||
|
|
||
| @Test | ||
| void doubleArrayToFloatsConvertsCorrectly() { | ||
| double[] doubles = {1.0, 2.5, -3.0}; | ||
| float[] floats = ArrayUtils.doubleArrayToFloats(doubles); | ||
| assertThat(floats).hasSize(3); | ||
| assertThat(floats[0]).isCloseTo(1.0f, org.assertj.core.data.Offset.offset(0.001f)); | ||
| assertThat(floats[1]).isCloseTo(2.5f, org.assertj.core.data.Offset.offset(0.001f)); | ||
| assertThat(floats[2]).isCloseTo(-3.0f, org.assertj.core.data.Offset.offset(0.001f)); | ||
| } | ||
|
|
||
| @Test | ||
| void doubleArrayToFloatsNullReturnsNull() { | ||
| assertThat(ArrayUtils.doubleArrayToFloats(null)).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void emptyFloatArrayRoundTrips() { | ||
| float[] empty = {}; | ||
| byte[] bytes = ArrayUtils.floatArrayToBytes(empty); | ||
| float[] result = ArrayUtils.bytesToFloatArray(bytes); | ||
| assertThat(result).isEmpty(); | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
core/src/test/java/com/redis/vl/utils/FullTextQueryHelperTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package com.redis.vl.utils; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.util.Set; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class FullTextQueryHelperTest { | ||
|
|
||
| @Test | ||
| void loadDefaultStopwordsReturnsNonEmptySetForEnglish() { | ||
| Set<String> stopwords = FullTextQueryHelper.loadDefaultStopwords("english"); | ||
| assertThat(stopwords).isNotEmpty().contains("the", "and", "is"); | ||
| } | ||
|
|
||
| @Test | ||
| void loadDefaultStopwordsReturnsEmptySetForUnknownLanguage() { | ||
| Set<String> stopwords = FullTextQueryHelper.loadDefaultStopwords("klingon"); | ||
| assertThat(stopwords).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void loadDefaultStopwordsReturnsEmptySetForNullLanguage() { | ||
| assertThat(FullTextQueryHelper.loadDefaultStopwords(null)).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void loadDefaultStopwordsReturnsEmptySetForEmptyLanguage() { | ||
| assertThat(FullTextQueryHelper.loadDefaultStopwords("")).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void tokenizeAndEscapeQueryFiltersStopwords() { | ||
| Set<String> stopwords = Set.of("the", "is", "a"); | ||
| String result = FullTextQueryHelper.tokenizeAndEscapeQuery("the cat is a dog", stopwords); | ||
| assertThat(result).doesNotContain("the").doesNotContain("is").doesNotContain(" a "); | ||
| assertThat(result).contains("cat").contains("dog"); | ||
| } | ||
|
|
||
| @Test | ||
| void tokenizeAndEscapeQueryJoinsWithPipe() { | ||
| Set<String> stopwords = Set.of(); | ||
| String result = FullTextQueryHelper.tokenizeAndEscapeQuery("foo bar", stopwords); | ||
| assertThat(result).isEqualTo("foo | bar"); | ||
| } | ||
|
|
||
| @Test | ||
| void tokenizeAndEscapeQueryEscapesSpecialChars() { | ||
| Set<String> stopwords = Set.of(); | ||
| String result = FullTextQueryHelper.tokenizeAndEscapeQuery("hello-world", stopwords); | ||
| assertThat(result).contains("\\-"); | ||
| } | ||
|
|
||
| @Test | ||
| void tokenizeAndEscapeQueryLowercasesTokens() { | ||
| Set<String> stopwords = Set.of(); | ||
| String result = FullTextQueryHelper.tokenizeAndEscapeQuery("Hello World", stopwords); | ||
| assertThat(result).isEqualTo("hello | world"); | ||
| } | ||
|
|
||
| @Test | ||
| void tokenizeAndEscapeQueryHandlesExtraWhitespace() { | ||
| Set<String> stopwords = Set.of(); | ||
| String result = FullTextQueryHelper.tokenizeAndEscapeQuery("foo bar", stopwords); | ||
| assertThat(result).isEqualTo("foo | bar"); | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
core/src/test/java/com/redis/vl/utils/TokenEscaperTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package com.redis.vl.utils; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class TokenEscaperTest { | ||
|
|
||
| private TokenEscaper escaper; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| escaper = new TokenEscaper(); | ||
| } | ||
|
|
||
| @Test | ||
| void escapeReturnsUnchangedStringWithNoSpecialChars() { | ||
| assertThat(escaper.escape("hello")).isEqualTo("hello"); | ||
| } | ||
|
|
||
| @Test | ||
| void escapesSpaces() { | ||
| assertThat(escaper.escape("hello world")).isEqualTo("hello\\ world"); | ||
| } | ||
|
|
||
| @Test | ||
| void escapesComma() { | ||
| assertThat(escaper.escape("a,b")).isEqualTo("a\\,b"); | ||
| } | ||
|
|
||
| @Test | ||
| void escapesDot() { | ||
| assertThat(escaper.escape("file.txt")).isEqualTo("file\\.txt"); | ||
| } | ||
|
|
||
| @Test | ||
| void escapesHyphen() { | ||
| assertThat(escaper.escape("well-known")).isEqualTo("well\\-known"); | ||
| } | ||
|
|
||
| @Test | ||
| void escapesAtSign() { | ||
| assertThat(escaper.escape("user@example.com")).isEqualTo("user\\@example\\.com"); | ||
| } | ||
|
|
||
| @Test | ||
| void escapesMultipleSpecialChars() { | ||
| assertThat(escaper.escape("(test)")).isEqualTo("\\(test\\)"); | ||
| } | ||
|
|
||
| @Test | ||
| void escapeEmptyStringReturnsEmpty() { | ||
| assertThat(escaper.escape("")).isEqualTo(""); | ||
| } | ||
|
|
||
| @Test | ||
| void escapeNullThrowsIllegalArgumentException() { | ||
| assertThatThrownBy(() -> escaper.escape(null)) | ||
| .isInstanceOf(IllegalArgumentException.class) | ||
| .hasMessageContaining("null"); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.