Skip to content

Commit 6320201

Browse files
authored
Add tolerance for matrix stats agg variance value assertion (#18367)
* Add tolerance for matrix stats agg variance value assertion Signed-off-by: kkewwei <[email protected]> Signed-off-by: kkewwei <[email protected]> * fix spot violations Signed-off-by: kkewwei <[email protected]> Signed-off-by: kkewwei <[email protected]> * use same delta Signed-off-by: kkewwei <[email protected]> Signed-off-by: kkewwei <[email protected]> --------- Signed-off-by: kkewwei <[email protected]> Signed-off-by: kkewwei <[email protected]>
1 parent fe22c29 commit 6320201

File tree

1 file changed

+15
-10
lines changed
  • client/rest-high-level/src/test/java/org/opensearch/client

1 file changed

+15
-10
lines changed

client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,17 +566,22 @@ public void testSearchWithMatrixStats() throws IOException {
566566
assertEquals(1, searchResponse.getAggregations().asList().size());
567567
MatrixStats matrixStats = searchResponse.getAggregations().get("agg1");
568568
assertEquals(5, matrixStats.getFieldCount("num"));
569-
assertEquals(56d, matrixStats.getMean("num"), 0d);
570-
assertEquals(1830.0000000000002, matrixStats.getVariance("num"), 1.0e-12);
571-
assertEquals(0.09340198804973039, matrixStats.getSkewness("num"), 0d);
572-
assertEquals(1.2741646510794589, matrixStats.getKurtosis("num"), 0d);
569+
assertEqualsOnDouble(56d, matrixStats.getMean("num"));
570+
assertEqualsOnDouble(1830.0000000000002, matrixStats.getVariance("num"));
571+
assertEqualsOnDouble(0.09340198804973039, matrixStats.getSkewness("num"));
572+
assertEqualsOnDouble(1.2741646510794589, matrixStats.getKurtosis("num"));
573573
assertEquals(5, matrixStats.getFieldCount("num2"));
574-
assertEquals(29d, matrixStats.getMean("num2"), 0d);
575-
assertEquals(330d, matrixStats.getVariance("num2"), 1.0e-12);
576-
assertEquals(-0.13568039346585542, matrixStats.getSkewness("num2"), 1.0e-16);
577-
assertEquals(1.3517561983471071, matrixStats.getKurtosis("num2"), 0d);
578-
assertEquals(-767.5, matrixStats.getCovariance("num", "num2"), 0d);
579-
assertEquals(-0.9876336291667923, matrixStats.getCorrelation("num", "num2"), 0d);
574+
assertEqualsOnDouble(29d, matrixStats.getMean("num2"));
575+
assertEqualsOnDouble(330d, matrixStats.getVariance("num2"));
576+
assertEqualsOnDouble(-0.13568039346585542, matrixStats.getSkewness("num2"));
577+
assertEqualsOnDouble(1.3517561983471071, matrixStats.getKurtosis("num2"));
578+
assertEqualsOnDouble(-767.5, matrixStats.getCovariance("num", "num2"));
579+
assertEqualsOnDouble(-0.9876336291667923, matrixStats.getCorrelation("num", "num2"));
580+
}
581+
582+
private void assertEqualsOnDouble(double expected, double actual) {
583+
// Concurrent search could have small difference in floating-point results when merging from different way of slicing shard.
584+
assertEquals(expected, actual, 1.0e-12);
580585
}
581586

582587
public void testSearchWithParentJoin() throws IOException {

0 commit comments

Comments
 (0)