BAEL-6846 - tests revision due to article updates

This commit is contained in:
mcasari 2023-10-03 23:41:11 +02:00
parent d0ca3f2c17
commit 7e1d5991e6
1 changed files with 4 additions and 12 deletions

View File

@ -17,40 +17,32 @@ class FloatToBigDecimalUnitTest {
@Test
public void whenCreatedFromFloat_thenMatchesInternallyStoredValue() {
float floatToConvert = 1.1f;
float floatToConvert = 1.10000002384185791015625f;
BigDecimal bdFromFloat = new BigDecimal(floatToConvert);
assertEquals("1.10000002384185791015625", bdFromFloat.toString());
}
@Test
public void whenCreatedFromString_thenPreservesTheOriginal() {
BigDecimal bdFromString = new BigDecimal("1.1");
assertEquals("1.1", bdFromString.toString());
BigDecimal bdFromString = new BigDecimal("1.10000002384185791015625");
assertEquals("1.10000002384185791015625", bdFromString.toString());
}
@Test
public void whenCreatedFromFloatConvertedToString_thenFloatInternalValueGetsTruncated() {
String floatValue = Float.toString(1.1f);
String floatValue = Float.toString(1.10000002384185791015625f);
BigDecimal bdFromString = new BigDecimal(floatValue);
assertEquals("1.1", floatValue);
assertEquals("1.1", bdFromString.toString());
}
@Test
public void whenFloatConvertedToString_thenGetsTruncated() {
String floatValue = Float.toString(1.10000002384185791015625f);
assertEquals("1.1", floatValue);
}
@Test
public void whenCreatedByValueOf_thenFloatValueGetsTruncated() {
assertEquals("1.100000023841858", BigDecimal.valueOf(1.1f).toString());
assertEquals("1.100000023841858", BigDecimal.valueOf(1.10000002384185791015625f).toString());
}
@Test
public void whenDoubleConvertsFloatToString_thenFloatValueGetsTruncated() {
assertEquals("1.100000023841858", Double.toString(1.1f));
assertEquals("1.100000023841858", Double.toString(1.10000002384185791015625f));
}