Skip to content

Commit

Permalink
fixup! fix: use appropriate methods to convert the numbers in XML
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuelaepure10 committed Jun 10, 2024
1 parent d2123e9 commit 02e1dd2
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,18 @@ class StreamGmlWriter2Test {
void testNumbers() throws Exception {
/**test DOUBLE numbers*/
testNumber("doubleNumber", 12345.123456789, null)
testNumber("doubleNumber", 12345.123456789, "12345.123456789")
double doubleNumber = 123456789.123456789
double expected = java.lang.Double.parseDouble(doubleNumber.toString())
testNumber("doubleSimpleNumber", doubleNumber, expected)
testNumber("doubleSimpleNumber", doubleNumber, expected.toString())
testFloatingPointNumber(doubleNumber, "doubleNumber")

/**test INT, SHORT numbers*/
testNumber("integerNumber", 12345, null)
testNumber("integerNumber", 12345, "12345")
testNumber("shortNumber", 12345 as short, null)

testNumber("shortNumber", 12345 as short, "12345")

float smallDecimal = 0.12345F
float largeDecimal = 12345.6789F
Expand All @@ -405,10 +408,15 @@ class StreamGmlWriter2Test {
float maxFloat = Float.MAX_VALUE
float minFloat = Float.MIN_VALUE

// for Float and Double we are expecting to use using scientific notation
testFloatingPointNumber(smallDecimal, "floatNumber")
testNumber("floatNumber", smallDecimal, "0.12345")
testFloatingPointNumber(largeDecimal, "floatNumber")
testNumber("floatNumber", largeDecimal, "12345.679")
testFloatingPointNumber(verySmall, "floatNumber")
testNumber("floatNumber", verySmall, "1.0E-7")
testFloatingPointNumber(veryLarge, "floatNumber")
testNumber("floatNumber", veryLarge, "1.2345679E7")
testFloatingPointNumber(negative, "floatNumber")
testFloatingPointNumber(scientific, "floatNumber")
testFloatingPointNumber(maxFloat, "floatNumber")
Expand All @@ -427,8 +435,8 @@ class StreamGmlWriter2Test {
long nearMaxLong = 9223372036854775806L
long nearMinLong = -9223372036854775807L

testNumber("longNumber", smallPositive, null)
testNumber("longNumber", largePositive, null)
testNumber("longNumber", smallPositive, "12345")
testNumber("longNumber", largePositive, "1234567890123456789")
testNumber("longNumber", smallNegative, null)
testNumber("longNumber", largeNegative, null)
testNumber("longNumber", maxLong, null)
Expand All @@ -448,6 +456,7 @@ class StreamGmlWriter2Test {

String numberAsString = "1.23456789123456789E8"
testNumber("decimalNumber", new BigDecimal(numberAsString), null)
testNumber("decimalNumber", new BigDecimal(numberAsString), "123456789.123456789")
}

void testNumber(String elementName, number, expected) throws Exception {
Expand All @@ -464,11 +473,16 @@ class StreamGmlWriter2Test {

String actualText = xml.featureMember.PrimitiveTest."$elementName".text()
if (expected != null) {
compareValues(expected, actualText)
if (expected instanceof String) {
assertEquals(expected.toString(), xml.featureMember.PrimitiveTest."$elementName".text())
} else {
compareValues(expected, actualText)
}
} else {
compareValues(number, actualText)
}


if (DEL_TEMP_FILES) {
outFile.delete()
}
Expand All @@ -493,6 +507,7 @@ class StreamGmlWriter2Test {

void testFloatingPointNumber(floatNumber, type) {
def expected = java.lang.Double.parseDouble(floatNumber.toString())
println expected
testNumber(type, floatNumber, expected)
}

Expand Down

0 comments on commit 02e1dd2

Please sign in to comment.