@@ -24,14 +24,14 @@ import org.scalatest.PrivateMethodTester
2424import scala .language .postfixOps
2525
2626class DecimalSuite extends SparkFunSuite with PrivateMethodTester {
27- test(" creating decimals" ) {
28- /** Check that a Decimal has the given string representation, precision and scale */
29- def checkDecimal (d : Decimal , string : String , precision : Int , scale : Int ): Unit = {
30- assert(d.toString === string)
31- assert(d.precision === precision)
32- assert(d.scale === scale)
33- }
27+ /** Check that a Decimal has the given string representation, precision and scale */
28+ private def checkDecimal (d : Decimal , string : String , precision : Int , scale : Int ): Unit = {
29+ assert(d.toString === string)
30+ assert(d.precision === precision)
31+ assert(d.scale === scale)
32+ }
3433
34+ test(" creating decimals" ) {
3535 checkDecimal(new Decimal (), " 0" , 1 , 0 )
3636 checkDecimal(Decimal (BigDecimal (" 10.030" )), " 10.030" , 5 , 3 )
3737 checkDecimal(Decimal (BigDecimal (" 10.030" ), 4 , 1 ), " 10.0" , 4 , 1 )
@@ -53,6 +53,15 @@ class DecimalSuite extends SparkFunSuite with PrivateMethodTester {
5353 intercept[IllegalArgumentException ](Decimal (1e17 .toLong, 17 , 0 ))
5454 }
5555
56+ test(" creating decimals with negative scale" ) {
57+ checkDecimal(Decimal (BigDecimal (" 98765" ), 5 , - 3 ), " 9.9E+4" , 5 , - 3 )
58+ checkDecimal(Decimal (BigDecimal (" 314.159" ), 6 , - 2 ), " 3E+2" , 6 , - 2 )
59+ checkDecimal(Decimal (BigDecimal (1.579e12 ), 4 , - 9 ), " 1.579E+12" , 4 , - 9 )
60+ checkDecimal(Decimal (BigDecimal (1.579e12 ), 4 , - 10 ), " 1.58E+12" , 4 , - 10 )
61+ checkDecimal(Decimal (103050709L , 9 , - 10 ), " 1.03050709E+18" , 9 , - 10 )
62+ checkDecimal(Decimal (1e8 .toLong, 10 , - 10 ), " 1.00000000E+18" , 10 , - 10 )
63+ }
64+
5665 test(" double and long values" ) {
5766 /** Check that a Decimal converts to the given double and long values */
5867 def checkValues (d : Decimal , doubleValue : Double , longValue : Long ): Unit = {
0 commit comments