Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
more tests
  • Loading branch information
cloud-fan committed Oct 24, 2019
commit 48b7ef4c42c2bf98ffda16e77e2ef10bd78f5d9f
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.apache.spark.unsafe.types.CalendarInterval._

class IntervalUtilsSuite extends SparkFunSuite {

test("fromString") {
test("fromString: basic") {
testSingleUnit("YEAR", 3, 36, 0)
testSingleUnit("Month", 3, 3, 0)
testSingleUnit("Week", 3, 0, 3 * MICROS_PER_WEEK)
Expand Down Expand Up @@ -60,6 +60,23 @@ class IntervalUtilsSuite extends SparkFunSuite {
}
}

test("fromString: random order field") {
val input = "1 day 1 year"
val result = new CalendarInterval(12, MICROS_PER_DAY)
assert(fromString(input) == result)
}

test("fromString: duplicated fields") {
val input = "1 day 1 day"
val result = new CalendarInterval(0, 2 * MICROS_PER_DAY)
assert(fromString(input) == result)
}

test("fromString: value with +/-") {
val input = "+1 year -1 day"
val result = new CalendarInterval(12, -MICROS_PER_DAY)
assert(fromString(input) == result)
}

private def testSingleUnit(unit: String, number: Int, months: Int, microseconds: Long): Unit = {
for (prefix <- Seq("interval ", "")) {
Expand Down