diff --git a/muted-tests.yml b/muted-tests.yml index ddb50c5a829f9..f60d16d373f32 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -103,9 +103,6 @@ tests: - class: org.elasticsearch.xpack.sql.qa.single_node.JdbcSqlSpecIT method: test {case-functions.testUcaseInline3} issue: https://github.com/elastic/elasticsearch/issues/112643 -- class: org.elasticsearch.script.StatsSummaryTests - method: testEqualsAndHashCode - issue: https://github.com/elastic/elasticsearch/issues/112439 - class: org.elasticsearch.repositories.blobstore.testkit.analyze.HdfsRepositoryAnalysisRestIT issue: https://github.com/elastic/elasticsearch/issues/112889 - class: org.elasticsearch.xpack.sql.qa.security.JdbcSqlSpecIT diff --git a/server/src/test/java/org/elasticsearch/script/StatsSummaryTests.java b/server/src/test/java/org/elasticsearch/script/StatsSummaryTests.java index 9cfa586de11ab..1e3fdb4e6a9ff 100644 --- a/server/src/test/java/org/elasticsearch/script/StatsSummaryTests.java +++ b/server/src/test/java/org/elasticsearch/script/StatsSummaryTests.java @@ -75,9 +75,21 @@ public void testEqualsAndHashCode() { assertThat(stats1, equalTo(stats2)); assertThat(stats1.hashCode(), equalTo(stats2.hashCode())); + // Accumulators with same sum, but different counts are not equals + stats1.accept(1); + stats1.accept(1); + stats2.accept(2); + assertThat(stats1.getSum(), equalTo(stats2.getSum())); + assertThat(stats1.getCount(), not(equalTo(stats2.getCount()))); + assertThat(stats1, not(equalTo(stats2))); + assertThat(stats1.hashCode(), not(equalTo(stats2.hashCode()))); + // Accumulators with different values are not equals - randomDoubles(randomIntBetween(0, 20)).forEach(stats1); - randomDoubles(randomIntBetween(0, 20)).forEach(stats2); + stats1.reset(); + stats2.reset(); + randomDoubles(randomIntBetween(1, 20)).forEach(stats1.andThen(v -> stats2.accept(v + randomDoubleBetween(0.0, 1.0, false)))); + assertThat(stats1.getCount(), equalTo(stats2.getCount())); + assertThat(stats1.getSum(), not(equalTo(stats2.getSum()))); assertThat(stats1, not(equalTo(stats2))); assertThat(stats1.hashCode(), not(equalTo(stats2.hashCode()))); }