@Test public void shouldRoundNumbersGreaterThan10() { assertThat(ops.roundUp(-101, 0), is(-101)); assertThat(ops.roundUp(-101, 1), is(-101)); assertThat(ops.roundUp(-101, 1), is(-101)); assertThat(ops.roundUp(-101, -1), is(-100)); assertThat(ops.roundUp(-109, -1), is(-110)); assertThat(ops.roundUp(101, 0), is(101)); assertThat(ops.roundUp(101, 0), is(101)); assertThat(ops.roundUp(101, 1), is(101)); assertThat(ops.roundUp(101, 1), is(101)); assertThat(ops.roundUp(109, -1), is(110)); assertThat(ops.roundUp(101, -1), is(100)); }
@Override public Integer roundUp( Integer value, int decimalShift ) { if (value == 0) return 0; if (decimalShift >= 0) return value; int shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10; shiftedValueP5 += 5l; int shiftedValue = shiftedValueP5 / 10; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10; return shiftedValue; }
IntegerOperations implements MathOperations<Integer>, Comparator<Integer> { @Override public Integer roundUp( Integer value, int decimalShift ) { if (value == 0) return 0; if (decimalShift >= 0) return value; int shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10; shiftedValueP5 += 5l; int shiftedValue = shiftedValueP5 / 10; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10; return shiftedValue; } }
IntegerOperations implements MathOperations<Integer>, Comparator<Integer> { @Override public Integer roundUp( Integer value, int decimalShift ) { if (value == 0) return 0; if (decimalShift >= 0) return value; int shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10; shiftedValueP5 += 5l; int shiftedValue = shiftedValueP5 / 10; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10; return shiftedValue; }  }
IntegerOperations implements MathOperations<Integer>, Comparator<Integer> { @Override public Integer roundUp( Integer value, int decimalShift ) { if (value == 0) return 0; if (decimalShift >= 0) return value; int shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10; shiftedValueP5 += 5l; int shiftedValue = shiftedValueP5 / 10; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10; return shiftedValue; }  @Override Class<Integer> getOperandClass(); @Override Integer add( Integer value1,
                        Integer value2 ); @Override Integer subtract( Integer value1,
                             Integer value2 ); @Override Integer multiply( Integer value1,
                             Integer value2 ); @Override double divide( Integer value1,
                          Integer value2 ); @Override Integer negate( Integer value ); @Override Integer increment( Integer value ); @Override Integer maximum( Integer value1,
                            Integer value2 ); @Override Integer minimum( Integer value1,
                            Integer value2 ); @Override int compare( Integer value1,
                        Integer value2 ); @Override BigDecimal asBigDecimal( Integer value ); @Override Integer fromBigDecimal( BigDecimal value ); @Override Integer createZeroValue(); @Override Integer create( int value ); @Override Integer create( long value ); @Override Integer create( double value ); @Override double sqrt( Integer value ); @Override Comparator<Integer> getComparator(); @Override Integer random( Integer minimum,
                           Integer maximum,
                           Random rng ); @Override double doubleValue( Integer value ); @Override float floatValue( Integer value ); @Override int intValue( Integer value ); @Override long longValue( Integer value ); @Override short shortValue( Integer value ); @Override int getExponentInScientificNotation( Integer value ); @Override Integer roundUp( Integer value,
                            int decimalShift ); @Override Integer roundDown( Integer value,
                              int decimalShift ); @Override Integer keepSignificantFigures( Integer value,
                                           int numSigFigs ); }
IntegerOperations implements MathOperations<Integer>, Comparator<Integer> { @Override public Integer roundUp( Integer value, int decimalShift ) { if (value == 0) return 0; if (decimalShift >= 0) return value; int shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10; shiftedValueP5 += 5l; int shiftedValue = shiftedValueP5 / 10; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10; return shiftedValue; }  @Override Class<Integer> getOperandClass(); @Override Integer add( Integer value1,
                        Integer value2 ); @Override Integer subtract( Integer value1,
                             Integer value2 ); @Override Integer multiply( Integer value1,
                             Integer value2 ); @Override double divide( Integer value1,
                          Integer value2 ); @Override Integer negate( Integer value ); @Override Integer increment( Integer value ); @Override Integer maximum( Integer value1,
                            Integer value2 ); @Override Integer minimum( Integer value1,
                            Integer value2 ); @Override int compare( Integer value1,
                        Integer value2 ); @Override BigDecimal asBigDecimal( Integer value ); @Override Integer fromBigDecimal( BigDecimal value ); @Override Integer createZeroValue(); @Override Integer create( int value ); @Override Integer create( long value ); @Override Integer create( double value ); @Override double sqrt( Integer value ); @Override Comparator<Integer> getComparator(); @Override Integer random( Integer minimum,
                           Integer maximum,
                           Random rng ); @Override double doubleValue( Integer value ); @Override float floatValue( Integer value ); @Override int intValue( Integer value ); @Override long longValue( Integer value ); @Override short shortValue( Integer value ); @Override int getExponentInScientificNotation( Integer value ); @Override Integer roundUp( Integer value,
                            int decimalShift ); @Override Integer roundDown( Integer value,
                              int decimalShift ); @Override Integer keepSignificantFigures( Integer value,
                                           int numSigFigs );  }