Skip to content

Instantly share code, notes, and snippets.

@fsarradin
Created July 31, 2013 11:44
Show Gist options
  • Save fsarradin/6121311 to your computer and use it in GitHub Desktop.
Save fsarradin/6121311 to your computer and use it in GitHub Desktop.
ScalaTest + ScalaCheck to test Java
import objectx.WeightedPoint
import objects.Pair
import org.scalacheck.Arbitrary
import org.scalatest.FreeSpec
import org.scalatest.matchers.MustMatchers
import org.scalatest.prop.Checkers
class PartitionCheck extends FreeSpec with Checkers with MustMatchers {
import WeightedPointCalculator._ // there is some Java here!
import test.utils.TestUtil._
import scala.collection.convert.wrapAll._
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop._
"should get a pair of lower and higher weight1 volatilities when partition by weight1" in {
implicit val weightedPointWithArbitraryWeight1: Arbitrary[WeightedPoint] =
Arbitrary(arbitrary[Int] map (weight1 => createWeightedPoint(weight1, 0.0, 0.0)))
check((weight1: Int, surface: List[WeightedPoint]) => {
val result: Pair[java.util.List[WeightedPoint], java.util.List[WeightedPoint]] =
partitionByWeight1(new Weight1Enumeration(weight1), surface)
((result.getFirst forall (volatility => volatility.getWeight1.getCode < weight1))
&& (result.getSecond forall (volatility => volatility.getWeight1.getCode >= weight1)))
})
}
"should get a pair of lower and higher weight2 volatilities when partition by weight2" in {
implicit val weightedPointWithArbitraryWeight2: Arbitrary[WeightedPoint] =
Arbitrary(arbitrary[Double] map (weight2 => createWeightedPoint(1, weight2, 0.0)))
check((weight2: Double, surface: List[WeightedPoint]) => {
val result: Pair[java.util.List[WeightedPoint], java.util.List[WeightedPoint]] =
partitionByWeight2(weight2, surface)
((result.getFirst forall (volatility => volatility.getWeight2 < weight2))
&& (result.getSecond forall (volatility => volatility.getWeight2 >= weight2)))
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment