< prev index next >

test/java/text/Format/NumberFormat/NumberTest.java

Print this page




 385         }
 386     }
 387 
 388     public void TestIntegerFormat() throws ParseException {
 389         NumberFormat format = NumberFormat.getIntegerInstance(Locale.GERMANY);
 390 
 391         float[] formatInput = { 12345.67f, -12345.67f, -0, 0 };
 392         String[] formatExpected = { "12.346", "-12.346", "0", "0" };
 393 
 394         for (int i = 0; i < formatInput.length; i++) {
 395             String result = format.format(formatInput[i]);
 396             if (!result.equals(formatExpected[i])) {
 397                 errln("FAIL: Expected " + formatExpected[i] + ", got " + result);
 398             }
 399         }
 400 
 401         String[] parseInput = { "0", "-0", "12.345,67", "-12.345,67" };
 402         float[] parseExpected = { 0, 0, 12345, -12345 };
 403 
 404         for (int i = 0; i < parseInput.length; i++) {
 405             float result = ((Number) format.parse(parseInput[i])).floatValue();
 406             if (result != parseExpected[i]) {
 407                 errln("FAIL: Expected " + parseExpected[i] + ", got " + result);
 408             }
 409         }
 410     }
 411 }


 385         }
 386     }
 387 
 388     public void TestIntegerFormat() throws ParseException {
 389         NumberFormat format = NumberFormat.getIntegerInstance(Locale.GERMANY);
 390 
 391         float[] formatInput = { 12345.67f, -12345.67f, -0, 0 };
 392         String[] formatExpected = { "12.346", "-12.346", "0", "0" };
 393 
 394         for (int i = 0; i < formatInput.length; i++) {
 395             String result = format.format(formatInput[i]);
 396             if (!result.equals(formatExpected[i])) {
 397                 errln("FAIL: Expected " + formatExpected[i] + ", got " + result);
 398             }
 399         }
 400 
 401         String[] parseInput = { "0", "-0", "12.345,67", "-12.345,67" };
 402         float[] parseExpected = { 0, 0, 12345, -12345 };
 403 
 404         for (int i = 0; i < parseInput.length; i++) {
 405             float result = format.parse(parseInput[i]).floatValue();
 406             if (result != parseExpected[i]) {
 407                 errln("FAIL: Expected " + parseExpected[i] + ", got " + result);
 408             }
 409         }
 410     }
 411 }
< prev index next >