Introduced jmh benchmarking (#2549)

This commit is contained in:
ramansahasi
2017-09-04 19:52:28 +05:30
committed by maibin
parent 839a68f616
commit 133bbe1aca
6 changed files with 119 additions and 161 deletions

View File

@@ -9,7 +9,13 @@ import org.junit.runner.RunWith;
@RunWith(Theories.class)
public class NumberOfDigitsIntegrationTest {
private static NumberOfDigits numberOfDigits;
static {
numberOfDigits = new NumberOfDigits();
}
@DataPoints
public static int[][] lowestIntegers()
{
@@ -64,37 +70,37 @@ public class NumberOfDigitsIntegrationTest {
@Theory
public void givenDataPoints_whenStringBasedSolutionInvoked_thenAllPointsMatch(final int[] entry) {
Assume.assumeTrue(entry[0] > 0 && entry[1] > 0);
Assert.assertEquals(entry[0], NumberOfDigits.stringBasedSolution(entry[1]));
Assert.assertEquals(entry[0], numberOfDigits.stringBasedSolution(entry[1]));
}
@Theory
public void givenDataPoints_whenLogarithmicApproachInvoked_thenAllPointsMatch(final int[] entry) {
Assume.assumeTrue(entry[0] > 0 && entry[1] > 0);
Assert.assertEquals(entry[0], NumberOfDigits.logarithmicApproach(entry[1]));
Assert.assertEquals(entry[0], numberOfDigits.logarithmicApproach(entry[1]));
}
@Theory
public void givenDataPoints_whenRepeatedMultiplicationInvoked_thenAllPointsMatch(final int[] entry) {
Assume.assumeTrue(entry[0] > 0 && entry[1] > 0);
Assert.assertEquals(entry[0], NumberOfDigits.repeatedMultiplication(entry[1]));
Assert.assertEquals(entry[0], numberOfDigits.repeatedMultiplication(entry[1]));
}
@Theory
public void givenDataPoints_whenShiftOperatorsInvoked_thenAllPointsMatch(final int[] entry) {
Assume.assumeTrue(entry[0] > 0 && entry[1] > 0);
Assert.assertEquals(entry[0], NumberOfDigits.shiftOperators(entry[1]));
Assert.assertEquals(entry[0], numberOfDigits.shiftOperators(entry[1]));
}
@Theory
public void givenDataPoints_whenDividingWithPowersOf2Invoked_thenAllPointsMatch(final int[] entry) {
Assume.assumeTrue(entry[0] > 0 && entry[1] > 0);
Assert.assertEquals(entry[0], NumberOfDigits.dividingWithPowersOf2(entry[1]));
Assert.assertEquals(entry[0], numberOfDigits.dividingWithPowersOf2(entry[1]));
}
@Theory
public void givenDataPoints_whenDivideAndConquerInvoked_thenAllPointsMatch(final int[] entry) {
Assume.assumeTrue(entry[0] > 0 && entry[1] > 0);
Assert.assertEquals(entry[0], NumberOfDigits.divideAndConquer(entry[1]));
Assert.assertEquals(entry[0], numberOfDigits.divideAndConquer(entry[1]));
}
}