Export to GitHub

disruptor - issue #7

Compute the expected result by using an arithmetic series instead of looping and adding


Posted on Aug 11, 2011 by Helpful Rabbit

Not an issue per se. I just noticed it when looking over the tests and it seemed strange.

The expected result for UniCast unit tests is computed by a loop and an accumulator. An arithmetic series could be used instead. Also the code is duplicated.

Added getArithmeticSeries to Utils and removed duplication.

Perhaps a less general formula like n(n-1)/2 and single parameter method could be used instead for simplicity.

Attachments

Comment #1

Posted on Aug 30, 2011 by Helpful Rhino

This is an enhancement, not a defect.

Comment #2

Posted on Aug 31, 2011 by Helpful Rhino

The change for this is done now. The test should loop over the results to compute the value in the same way as expected.

Comment #3

Posted on Aug 31, 2011 by Helpful Rabbit

Looking into the code I see the perfTestUtil does the same thing as before

public static long accumulatedAddition(final long iterations) { long temp = 0L; for (long i = 0L; i < iterations; i++) { temp += i; }

    return temp;
}

Is there a reason why this result is not computed as suggested?

public static long accumulatedAddition(final long iterations)
{
  return iterations * (iterations - 1) / 2;
}

http://mathworld.wolfram.com/ArithmeticSeries.html

Thanks

Status: Fixed

Labels:
Priority-Medium Type-Enhancement