eclipse-collections icon indicating copy to clipboard operation
eclipse-collections copied to clipboard

Fix flaky test ParallelIterableTestCase#sumOfFloatConsistentRounding.

Open motlin opened this issue 1 year ago • 4 comments

This test sometimes fails with a delta greater than the allowed delta.

[ERROR]   ParallelCollectListIterableTest>ParallelIterableTestCase.sumOfFloatConsistentRounding:894 Batch size: 1000 ==> expected: <5.0000000000000995> but was: <5.000000000000101>

The test:

    @Test
    public void sumOfFloatConsistentRounding()
    {
        FloatFunction<Integer> roundingSensitiveElementFunction = i -> (i <= 99995) ? 1.0e-18f : 1.0f;

        MutableList<Integer> list = Interval.oneTo(100_000).toList().shuffleThis();
        double baseline = this.getExpectedWith(list.toArray(new Integer[]{}))
                .sumOfFloat(roundingSensitiveElementFunction);

        for (Integer batchSize : BATCH_SIZES)
        {
            this.batchSize = batchSize;

            ParallelIterable<Integer> testCollection = this.newWith(list.toArray(new Integer[]{}));
            assertEquals(
                    baseline,
                    testCollection.sumOfFloat(roundingSensitiveElementFunction),
                    1.0e-15,
                    "Batch size: " + this.batchSize);
        }
    }

motlin avatar Sep 15 '24 21:09 motlin

@motlin , I think the test failure you're encountering in the ParallelIterableTestCase#sumOfFloatConsistentRounding is related to floating-point precision. The error message shows that the expected result is <5.0000000000000995>, but the actual result was <5.000000000000101>. This difference is very small and falls within a "flaky test" range because it depends on how floating-point arithmetic is handled internally, which can vary slightly across platforms or when using parallel processing.

IamLRBA avatar Oct 24 '24 20:10 IamLRBA

Please assign me to this issue so that i can try and solve it. Thanks!

IamLRBA avatar Oct 24 '24 20:10 IamLRBA

Assigned to you @IamLRBA !

motlin avatar Oct 24 '24 23:10 motlin

Thank you @motlin

IamLRBA avatar Oct 24 '24 23:10 IamLRBA