Browse files

Add a test for the bug that was found with BernoulliSampler not copyi…

…ng the complement param
  • Loading branch information...
1 parent e49b63c commit 3496879a3d3c8c77bc7825b8af4e3fe3b3ba5043 @holdenk committed Feb 11, 2014
Showing with 14 additions and 0 deletions.
  1. +14 −0 core/src/test/scala/org/apache/spark/util/random/RandomSamplerSuite.scala
View
14 core/src/test/scala/org/apache/spark/util/random/RandomSamplerSuite.scala
@@ -48,6 +48,20 @@ class RandomSamplerSuite extends FunSuite with BeforeAndAfter with EasyMockSugar
}
}
+ test("BernoulliSamplerWithRangeInverse") {
+ expecting {
+ for(x <- Seq(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)) {
+ random.nextDouble().andReturn(x)
+ }
+ }
+ whenExecuting(random)
+ {
+ val sampler = new BernoulliSampler[Int](0.25, 0.55, true)(random)
+ assert(sampler.sample(a.iterator).toList === List(1, 2, 6, 7, 8, 9))
+ }
+ }
+
+
test("BernoulliSamplerWithRatio") {
expecting {
for(x <- Seq(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)) {

0 comments on commit 3496879

Please sign in to comment.