Skip to content
Snippets Groups Projects
Commit 2990298f authored by Antonio's avatar Antonio
Browse files

Added sorting testing suite

parent 62079816
No related branches found
No related tags found
No related merge requests found
package spark
import scala.collection.mutable.HashMap
import org.scalatest.FunSuite
import SparkContext._
class SortingSuite extends FunSuite {
test("sortByKey") {
val sc = new SparkContext("local", "test")
val pairs = sc.parallelize(Array((1, 0), (2, 0), (0, 0), (3, 0)))
assert(pairs.sortByKey().collect() === Array((0,0), (1,0), (2,0), (3,0)))
sc.stop()
}
test("sortLargeArray") {
val sc = new SparkContext("local", "test")
val rand = new scala.util.Random()
val pairArr = Array.fill(1000) { (rand.nextInt(), rand.nextInt()) }
val pairs = sc.parallelize(pairArr)
assert(pairs.sortByKey().collect() === pairArr.sortBy(_._1))
sc.stop()
}
test("sortDescending") {
val sc = new SparkContext("local", "test")
val rand = new scala.util.Random()
val pairArr = Array.fill(1000) { (rand.nextInt(), rand.nextInt()) }
val pairs = sc.parallelize(pairArr)
assert(pairs.sortByKey(false).collect() === pairArr.sortWith((x, y) => x._1 > y._1))
sc.stop()
}
test("sortHighParallelism") {
val sc = new SparkContext("local", "test")
val rand = new scala.util.Random()
val pairArr = Array.fill(3000) { (rand.nextInt(), rand.nextInt()) }
val pairs = sc.parallelize(pairArr, 300)
assert(pairs.sortByKey().collect() === pairArr.sortBy(_._1))
sc.stop()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment