diff --git a/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/DcgSearchMetricTest.java b/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/DcgSearchMetricTest.java index bed5b2d..f3755f3 100644 --- a/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/DcgSearchMetricTest.java +++ b/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/DcgSearchMetricTest.java @@ -16,7 +16,7 @@ public class DcgSearchMetricTest extends OpenSearchTestCase { public void testCalculate() { - final int k = 5; + final int k = 10; final List relevanceScores = List.of(1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 0.0); final DcgSearchMetric dcgSearchMetric = new DcgSearchMetric(k, relevanceScores); @@ -26,4 +26,16 @@ public void testCalculate() { } + public void testCalculateAllZeros() { + + final int k = 10; + final List relevanceScores = List.of(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + + final DcgSearchMetric dcgSearchMetric = new DcgSearchMetric(k, relevanceScores); + final double dcg = dcgSearchMetric.calculate(); + + assertEquals(0.0, dcg, 0.0); + + } + } diff --git a/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/NdcgSearchMetricTest.java b/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/NdcgSearchMetricTest.java index b0d672b..08795f8 100644 --- a/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/NdcgSearchMetricTest.java +++ b/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/NdcgSearchMetricTest.java @@ -16,7 +16,7 @@ public class NdcgSearchMetricTest extends OpenSearchTestCase { public void testCalculate() { - final int k = 5; + final int k = 10; final List relevanceScores = List.of(1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 0.0); final NdcgSearchMetric ndcgSearchMetric = new NdcgSearchMetric(k, relevanceScores); @@ -26,4 +26,16 @@ public void testCalculate() { } + public void testCalculateAllZeros() { + + final int k = 10; + final List relevanceScores = List.of(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + + final NdcgSearchMetric ndcgSearchMetric = new NdcgSearchMetric(k, relevanceScores); + final double ndcg = ndcgSearchMetric.calculate(); + + assertEquals(0.0, ndcg, 0.0); + + } + } diff --git a/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/PrecisionSearchMetricTest.java b/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/PrecisionSearchMetricTest.java index 14f6c9a..b6c260f 100644 --- a/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/PrecisionSearchMetricTest.java +++ b/opensearch-search-quality-evaluation-plugin/src/test/java/org/opensearch/eval/metrics/PrecisionSearchMetricTest.java @@ -16,14 +16,14 @@ public class PrecisionSearchMetricTest extends OpenSearchTestCase { public void testCalculate() { - final int k = 5; + final int k = 10; final double threshold = 1.0; final List relevanceScores = List.of(1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 0.0); final PrecisionSearchMetric precisionSearchMetric = new PrecisionSearchMetric(k, threshold, relevanceScores); final double precision = precisionSearchMetric.calculate(); - assertEquals(1.8, precision, 0.0); + assertEquals(0.9, precision, 0.0); }