Skip to content
Browse files

Fixed more problems related to maxDiscardRatio and minSuccessfulTests.

  • Loading branch information...
1 parent a264712 commit 6fc6ffaf39ec9f6fb73b58e252811ba05880df49 @rickynils committed May 14, 2012
Showing with 22 additions and 21 deletions.
  1. +12 −9 src/main/scala/org/scalacheck/Test.scala
  2. +10 −12 src/test/scala/org/scalacheck/TestSpecification.scala
View
21 src/main/scala/org/scalacheck/Test.scala
@@ -163,18 +163,18 @@ object Test {
if(workers > 1)
assert(!p.isInstanceOf[Commands], "Commands cannot be checked multi-threaded")
- val iterations = minSuccessfulTests / (workers: Float)
- val sizeStep = (maxSize-minSize) / (minSuccessfulTests: Float)
+ val iterations = math.ceil(minSuccessfulTests / (workers: Double))
+ val sizeStep = (maxSize-minSize) / (iterations*workers)
var stop = false
- def worker(workerdIdx: Int) = future {
+ def worker(workerIdx: Int) = future {
var n = 0 // passed tests
var d = 0 // discarded tests
- var size = minSize + (workerdIdx*sizeStep*iterations)
var res: Result = null
var fm = FreqMap.empty[immutable.Set[Any]]
while(!stop && res == null && n < iterations) {
- val propPrms = Prop.Params(Gen.Params(size.round, prms.rng), fm)
+ val size = (minSize: Double) + (sizeStep * (workerIdx + (workers*(n+d))))
+ val propPrms = Prop.Params(Gen.Params(size.round.toInt, prms.rng), fm)
secure(p(propPrms)) match {
case Right(e) => res =
Result(GenException(e), n, d, FreqMap.empty[immutable.Set[Any]])
@@ -185,12 +185,16 @@ object Test {
propRes.status match {
case Prop.Undecided =>
d += 1
- testCallback.onPropEval("", workerdIdx, n, d)
- if ((n > minSuccessfulTests || d > minSuccessfulTests) && maxDiscardRatio*n < d)
+ testCallback.onPropEval("", workerIdx, n, d)
+ // The below condition is kind of hacky. We have to have
+ // some margin, otherwise workers will stop testing too
+ // early because they have been exhausted, but the overall
+ // test has not.
+ if (n+d >= minSuccessfulTests && workers*maxDiscardRatio*n < d)
res = Result(Exhausted, n, d, fm)
case Prop.True =>
n += 1
- testCallback.onPropEval("", workerdIdx, n, d)
+ testCallback.onPropEval("", workerIdx, n, d)
case Prop.Proof =>
n += 1
res = Result(Proved(propRes.args), n, d, fm)
@@ -203,7 +207,6 @@ object Test {
stop = true
}
}
- size += sizeStep
}
if (res == null) {
if (maxDiscardRatio*n > d) Result(Passed, n, d, fm)
View
22 src/test/scala/org/scalacheck/TestSpecification.scala
@@ -55,26 +55,24 @@ object TestSpecification extends Properties("Test") {
property("minSuccessfulTests") = forAll { (prms: Test.Params, p: Prop) =>
val r = Test.check(prms, p)
r.status match {
- case Passed => "Passed "+r.succeeded+" "+r.discarded |:
+ case Passed => r.status+", s="+r.succeeded+", d="+r.discarded |:
r.succeeded >= prms.minSuccessfulTests
- case Exhausted => "Exhausted "+r.succeeded+" "+r.discarded |:
+ case Exhausted => r.status+", s="+r.succeeded+", d="+r.discarded |:
r.succeeded + r.discarded >= prms.minSuccessfulTests
- case _ => r.status.toString+" "+r.succeeded+" "+r.discarded |:
- true
+ case _ => r.status+", s="+r.succeeded+", d="+r.discarded |:
+ r.succeeded < prms.minSuccessfulTests
}
}
property("maxDiscardRatio") = forAll { (prms: Test.Params, p: Prop) =>
val r = Test.check(prms, p)
r.status match {
- case Passed => "Passed "+r.succeeded+" "+r.discarded |:
- r.succeeded*prms.maxDiscardRatio >= r.discarded
- case Exhausted => "Exhausted "+r.succeeded+" "+r.discarded |:
- r.succeeded + r.discarded >= prms.minSuccessfulTests &&
- r.succeeded*prms.maxDiscardRatio < r.discarded
- case _ => r.status.toString+" "+r.succeeded+" "+r.discarded |:
- r.succeeded + r.discarded < prms.minSuccessfulTests ||
- r.succeeded*prms.maxDiscardRatio >= r.discarded
+ case Passed => r.status+", s="+r.succeeded+", d="+r.discarded |:
+ r.discarded <= prms.maxDiscardRatio*r.succeeded
+ case Exhausted => r.status+", s="+r.succeeded+", d="+r.discarded |:
+ r.discarded > prms.maxDiscardRatio*r.succeeded
+ case _ => r.status+", s="+r.succeeded+", d="+r.discarded |:
+ true
}
}

0 comments on commit 6fc6ffa

Please sign in to comment.
Something went wrong with that request. Please try again.