Skip to content

Commit

Permalink
create new test cases for takeSample from an empty red
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingCat committed Mar 13, 2014
1 parent 810948d commit 36db06b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/src/test/scala/org/apache/spark/rdd/RDDSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,7 @@ class RDDSuite extends FunSuite with SharedSparkContext {

test("takeSample") {
val data = sc.parallelize(1 to 100, 2)
val emptySet = data.mapPartitions { iter => Iterator.empty }

val sample = emptySet.takeSample(false, 20, 1)
assert(sample.length === 0)
for (seed <- 1 to 5) {
val sample = data.takeSample(withReplacement=false, 20, seed)
assert(sample.size === 20) // Got exactly 20 elements
Expand Down Expand Up @@ -492,6 +489,12 @@ class RDDSuite extends FunSuite with SharedSparkContext {
}
}

test("takeSample from an empty rdd") {
val emptySet = sc.parallelize(Seq.empty[Int], 2)
val sample = emptySet.takeSample(false, 20, 1)
assert(sample.length === 0)
}

test("randomSplit") {
val n = 600
val data = sc.parallelize(1 to n, 2)
Expand Down

0 comments on commit 36db06b

Please sign in to comment.