-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
core/src/test/spark_3.2_3.3_3.4/scala/doric/syntax/NumericOperations32Spec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package doric | ||
package syntax | ||
|
||
import doric.Equalities._ | ||
import doric.types.SparkType.Primitive | ||
import org.apache.spark.sql.SparkSession | ||
import org.scalactic.Equality | ||
import org.scalatest.funspec.AnyFunSpecLike | ||
|
||
import scala.reflect.ClassTag | ||
|
||
trait NumericOperations32Spec | ||
extends AnyFunSpecLike | ||
with TypedColumnTest | ||
with NumericUtilsSpec { | ||
|
||
import scala.reflect.runtime.universe._ | ||
|
||
def testDecimals32[ | ||
T: NumWithDecimalsType : Primitive : ClassTag : TypeTag : Equality | ||
]()(implicit | ||
spark: SparkSession, | ||
fun: FromFloat[T] | ||
): Unit = { | ||
val numTypeStr = getClassName[T] | ||
|
||
describe(s"Num with Decimals ( $numTypeStr )") { | ||
|
||
it(s"round function with scale and round mode") { | ||
val scale = 2 | ||
val mode = BigDecimal.RoundingMode.FLOOR | ||
testOnlyDoricDecimals[T, T]( | ||
List(Some(1.466666f), Some(0.7111111f), Some(1.0f), None), | ||
List(Some(1.46f), Some(0.71f), Some(1.0f), None), | ||
_.round(scale.lit, mode) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
class Numeric32Spec extends NumericOperations32Spec with SparkSessionTestWrapper { | ||
|
||
implicit val sparkSession: SparkSession = spark | ||
|
||
testDecimals32[Float]() | ||
testDecimals32[Double]() | ||
} |