Skip to content

Commit

Permalink
round out tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengruifeng committed Jan 19, 2018
1 parent ac067e7 commit f3a4329
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,18 @@ class VectorsSuite extends SparkMLFunSuite {
assert(v.slice(Array(2, 0)) === new SparseVector(2, Array(0), Array(2.2)))
assert(v.slice(Array(2, 0, 3, 4)) === new SparseVector(4, Array(0, 3), Array(2.2, 4.4)))
}

test("sparse vector only support non-negative length") {
val v1 = Vectors.sparse(0, Array.emptyIntArray, Array.emptyDoubleArray)
val v2 = Vectors.sparse(0, Array.empty[(Int, Double)])
assert(v1.size === 0)
assert(v2.size === 0)

intercept[IllegalArgumentException] {
Vectors.sparse(-1, Array(1), Array(2.0))
}
intercept[IllegalArgumentException] {
Vectors.sparse(-1, Array((1, 2.0)))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ class VectorsSuite extends SparkFunSuite with Logging {
assert(vec.toArray === arr)
}

test("zero-length sparse vector") {
val v1 = Vectors.sparse(0, Array.emptyIntArray, Array.emptyDoubleArray)
val v2 = Vectors.sparse(0, Array.empty[(Int, Double)])
assert(v1.size === 0)
assert(v2.size === 0)
}

test("sparse argmax") {
val vec = Vectors.sparse(0, Array.empty[Int], Array.empty[Double]).asInstanceOf[SparseVector]
assert(vec.argmax === -1)
Expand Down Expand Up @@ -502,4 +495,18 @@ class VectorsSuite extends SparkFunSuite with Logging {
assert(mlDenseVectorToArray(dv) === mlDenseVectorToArray(newDV))
assert(mlSparseVectorToArray(sv) === mlSparseVectorToArray(newSV))
}

test("sparse vector only support non-negative length") {
val v1 = Vectors.sparse(0, Array.emptyIntArray, Array.emptyDoubleArray)
val v2 = Vectors.sparse(0, Array.empty[(Int, Double)])
assert(v1.size === 0)
assert(v2.size === 0)

intercept[IllegalArgumentException] {
Vectors.sparse(-1, Array(1), Array(2.0))
}
intercept[IllegalArgumentException] {
Vectors.sparse(-1, Array((1, 2.0)))
}
}
}

0 comments on commit f3a4329

Please sign in to comment.