Skip to content

Commit

Permalink
test transformers with SparseVector output
Browse files Browse the repository at this point in the history
  • Loading branch information
nevillelyh committed Apr 10, 2018
1 parent cad761a commit b156bc1
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

package com.spotify.featran.transformers

import scala.collection.Set
import breeze.linalg.SparseVector

import scala.collection.Set
import com.spotify.featran.FeatureSpec
import org.scalacheck.Prop.BooleanOperators
import org.scalacheck._
Expand All @@ -42,6 +43,7 @@ abstract class TransformerProp(name: String) extends Properties(name) {
private def safeCompare(xs: List[Seq[Double]], ys: List[Seq[Double]]): Boolean =
xs.map(_.map(d2e)) == ys.map(_.map(d2e))

// scalastyle:off method.length
def test[T](t: Transformer[T, _, _],
input: List[T],
names: Seq[String],
Expand Down Expand Up @@ -75,6 +77,9 @@ abstract class TransformerProp(name: String) extends Properties(name) {
"f3 names" |: f3.featureNames == List(names),
"f4 names" |: f4.featureNames == List(names),
"f1 values" |: safeCompare(f1.featureValues[Seq[Double]], expected),
"f1 sparse values" |: safeCompare(
f1.featureValues[SparseVector[Double]].map(_.toDenseVector.data.toSeq),
expected),
"f1 rejections" |: safeCompare(rejections, rejected),
"f2 values" |: safeCompare(f2.featureValues[Seq[Double]], expected :+ missing),
"f3 values" |: safeCompare(f3.featureValues[Seq[Double]], expected.take(input.size / 2)),
Expand All @@ -92,6 +97,7 @@ abstract class TransformerProp(name: String) extends Properties(name) {
"f3 settings" |: settings == f3.featureSettings,
"f4 settings" |: settings == f4.featureSettings)
}
// scalastyle:on method.length

def testException[T](t: Transformer[T, _, _], input: List[T])(p: Throwable => Boolean): Prop =
try {
Expand Down

0 comments on commit b156bc1

Please sign in to comment.