From d2bea5ffd3c4f392f940f742656043c0a4612070 Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Mon, 12 Nov 2012 17:13:37 +0000 Subject: [PATCH] Add tests to show magnitude boundary between Float, Double and BigDecimal git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1408359 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/lang3/math/NumberUtilsTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java index 4aa7714f3..fdb079c44 100644 --- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java @@ -245,6 +245,20 @@ public void testCreateNumber() { } } + // Tests to show when magnitude causes switch to next Number type + // Will probably need to be adjusted if code is changed to check precision (LANG-693) + @Test + public void testCreateNumberMagnitude() { + // Test Float.MAX_VALUE, and same with +1 in final digit to check conversion changes to next Number type + assertEquals(Float.class, NumberUtils.createNumber("3.4028235e+38").getClass()); + assertEquals(Double.class, NumberUtils.createNumber("3.4028236e+38").getClass()); + + // Test Double.MAX_VALUE + assertEquals(Double.class, NumberUtils.createNumber("1.7976931348623157e+308").getClass()); + // Test with +2 in final digit (+1 does not cause roll-over to BigDecimal) + assertEquals(BigDecimal.class, NumberUtils.createNumber("1.7976931348623159e+308").getClass()); + } + @Test public void testCreateFloat() { assertEquals("createFloat(String) failed", Float.valueOf("1234.5"), NumberUtils.createFloat("1234.5"));