Skip to content

Commit

Permalink
add ut for 0-based loadlibsvm exception
Browse files Browse the repository at this point in the history
  • Loading branch information
hhbyyh committed May 31, 2015
1 parent 5bd1f9a commit 9956365
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import breeze.linalg.{squaredDistance => breezeSquaredDistance}
import com.google.common.base.Charsets
import com.google.common.io.Files

import org.apache.spark.SparkException
import org.apache.spark.mllib.linalg.{DenseVector, SparseVector, Vectors}
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.mllib.util.MLUtils._
Expand Down Expand Up @@ -109,6 +110,23 @@ class MLUtilsSuite extends FunSuite with MLlibTestSparkContext {
Utils.deleteRecursively(tempDir)
}

test("loadLibSVMFile throws SparkException when passing a zero-based vector") {
val lines =
"""
|0
|0 0:4.0 4:5.0 6:6.0
""".stripMargin
val tempDir = Utils.createTempDir()
val file = new File(tempDir.getPath, "part-00000")
Files.write(lines, file, Charsets.US_ASCII)
val path = tempDir.toURI.toString

intercept[SparkException] {
val pointsWithoutNumFeatures = loadLibSVMFile(sc, path).collect()
}
Utils.deleteRecursively(tempDir)
}

test("saveAsLibSVMFile") {
val examples = sc.parallelize(Seq(
LabeledPoint(1.1, Vectors.sparse(3, Seq((0, 1.23), (2, 4.56)))),
Expand Down

0 comments on commit 9956365

Please sign in to comment.