Utils { public static Double round(double d, int decimalPlace) { BigDecimal bd = new BigDecimal(Double.toString(d)); bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); }  static String cleanLine(String line); static String getFile(String FileName); static void writeFile(String in, String filename); static Double round(double d, int decimalPlace); static Double entropy(double[] p);  }
@Test public final void testRound() { double ress[] = { -10.0, 10.0, -110.0, 110.0, 0.0, -110.0, 0.0, 0.0, 1000.0, -1000.0, 1000.0, -1000.0, -11.0, 11.0, -105.0, 105.0, 1.0, -105.0, 0.0, 0.0, 1001.0, -1001.0, 1000.0, -1000.0, -10.5, 10.5, -105.1, 105.1, 1.1, -105.1, 0.0, 0.0, 1000.5, -1000.5, 1000.5, -1000.5, -10.51, 10.51, -105.1, 105.1, 1.05, -105.1, 0.0, 0.0, 1000.5, -1000.5, 1000.49, -1000.49, -10.51, 10.51, -105.1, 105.1, 1.051, -105.1, 0.0, 0.0, 1000.5, -1000.5, 1000.49, -1000.49, -10.51, 10.51, -105.1, 105.1, 1.051, -105.1, 0.0001, -0.0001, 1000.5, -1000.5, 1000.49, -1000.49, -10.51, 10.51, -105.1, 105.1, 1.051, -105.1, 0.0001, -0.0001, 1000.5, -1000.5, 1000.49, -1000.49 }; double arg1s[] = { -10.51, +10.51, -10.51e+1, +10.51e+1, +10.51e-1, -10.51e+1, +0.0001, -0.0001, +1000.5, -1000.5, +1000.49, -1000.49 }; int arg2s[] = {-1, 0,1,2,3,4,5}; for (int i=0; i<arg2s.length; i++) { for (int j=0; j<arg1s.length; j++) { double one = arg1s[j]; int two = arg2s[i]; double res = Utils.round(one, two); int inx = i*arg1s.length+j; assertEquals(res, ress[inx], TestDataManager.DELTA_DOUBLE); } } }