diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-06-21 00:27:20 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-06-21 00:27:20 -0700 |
commit | 513604f3f8252ec05d06de5f746788c222c1791d (patch) | |
tree | 4baa0326478143fe7b8d4a7e3cc0f0d87f57c573 /src | |
parent | 320a32b0b5902781b9fb13ad83083574a36f3e46 (diff) | |
parent | 10b44339c5fb4c35b57f5675a924b3c5de871c20 (diff) | |
download | scala-513604f3f8252ec05d06de5f746788c222c1791d.tar.gz scala-513604f3f8252ec05d06de5f746788c222c1791d.tar.bz2 scala-513604f3f8252ec05d06de5f746788c222c1791d.zip |
Merge pull request #748 from jsuereth/update-scalacheck-source
Updated scalacheck sources.
Diffstat (limited to 'src')
-rw-r--r-- | src/scalacheck/org/scalacheck/Arbitrary.scala | 36 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/Arg.scala | 2 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/Commands.scala | 23 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/ConsoleReporter.scala | 27 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/Gen.scala | 50 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/Pretty.scala | 4 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/Prop.scala | 36 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/Properties.scala | 2 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/Shrink.scala | 2 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/Test.scala | 191 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/util/Buildable.scala | 4 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/util/CmdLineParser.scala | 9 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/util/FreqMap.scala | 2 | ||||
-rw-r--r-- | src/scalacheck/org/scalacheck/util/StdRand.scala | 2 |
14 files changed, 144 insertions, 246 deletions
diff --git a/src/scalacheck/org/scalacheck/Arbitrary.scala b/src/scalacheck/org/scalacheck/Arbitrary.scala index 28e116b479..8c43cdaafe 100644 --- a/src/scalacheck/org/scalacheck/Arbitrary.scala +++ b/src/scalacheck/org/scalacheck/Arbitrary.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck @@ -178,9 +178,10 @@ object Arbitrary { import java.math.MathContext._ val mcGen = oneOf(UNLIMITED, DECIMAL32, DECIMAL64, DECIMAL128) val bdGen = for { - mc <- mcGen - scale <- arbInt.arbitrary x <- arbBigInt.arbitrary + mc <- mcGen + limit <- value(if(mc == UNLIMITED) 0 else math.max(x.abs.toString.length - mc.getPrecision, 0)) + scale <- Gen.chooseNum(Int.MinValue + limit , Int.MaxValue) } yield BigDecimal(x, scale, mc) Arbitrary(bdGen) } @@ -197,24 +198,37 @@ object Arbitrary { } /** Generates an arbitrary property */ - implicit lazy val arbProp: Arbitrary[Prop] = + implicit lazy val arbProp: Arbitrary[Prop] = { + import Prop._ + val undecidedOrPassed = forAll { b: Boolean => + b ==> true + } Arbitrary(frequency( - (5, Prop.proved), - (4, Prop.falsified), - (2, Prop.undecided), - (1, Prop.exception(null)) + (4, falsified), + (4, passed), + (3, proved), + (3, undecidedOrPassed), + (2, undecided), + (1, exception(null)) )) + } /** Arbitrary instance of test params */ implicit lazy val arbTestParams: Arbitrary[Test.Params] = Arbitrary(for { - minSuccTests <- choose(10,150) - maxDiscTests <- choose(100,500) + minSuccTests <- choose(10,200) + maxDiscardRatio <- choose(0.2f,10f) minSize <- choose(0,500) sizeDiff <- choose(0,500) maxSize <- choose(minSize, minSize + sizeDiff) ws <- choose(1,4) - } yield Test.Params(minSuccTests,maxDiscTests,minSize,maxSize,workers = ws)) + } yield Test.Params( + minSuccessfulTests = minSuccTests, + maxDiscardRatio = maxDiscardRatio, + minSize = minSize, + maxSize = maxSize, + workers = ws + )) /** Arbitrary instance of gen params */ implicit lazy val arbGenParams: Arbitrary[Gen.Params] = diff --git a/src/scalacheck/org/scalacheck/Arg.scala b/src/scalacheck/org/scalacheck/Arg.scala index 908bce2a81..8959211f09 100644 --- a/src/scalacheck/org/scalacheck/Arg.scala +++ b/src/scalacheck/org/scalacheck/Arg.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck diff --git a/src/scalacheck/org/scalacheck/Commands.scala b/src/scalacheck/org/scalacheck/Commands.scala index 112dda28a7..5ad82c513d 100644 --- a/src/scalacheck/org/scalacheck/Commands.scala +++ b/src/scalacheck/org/scalacheck/Commands.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck @@ -46,13 +46,6 @@ trait Commands extends Prop { def run(s: State): Any def nextState(s: State): State - /** @deprecated Use <code>preConditions += ...</code> instead. */ - @deprecated("Use 'preConditions += ...' instead.", "1.6") - def preCondition_=(f: State => Boolean) = { - preConditions.clear - preConditions += f - } - /** Returns all preconditions merged into a single function */ def preCondition: (State => Boolean) = s => preConditions.toList.forall(_.apply(s)) @@ -62,20 +55,6 @@ trait Commands extends Prop { * conditions to the precondition list */ val preConditions = new collection.mutable.ListBuffer[State => Boolean] - /** @deprecated Use <code>postConditions += ...</code> instead. */ - @deprecated("Use 'postConditions += ...' instead.", "1.6") - def postCondition_=(f: (State,Any) => Prop) = { - postConditions.clear - postConditions += ((s0,s1,r) => f(s0,r)) - } - - /** @deprecated Use <code>postConditions += ...</code> instead. */ - @deprecated("Use 'postConditions += ...' instead.", "1.6") - def postCondition_=(f: (State,State,Any) => Prop) = { - postConditions.clear - postConditions += f - } - /** Returns all postconditions merged into a single function */ def postCondition: (State,State,Any) => Prop = (s0,s1,r) => all(postConditions.map(_.apply(s0,s1,r)): _*) diff --git a/src/scalacheck/org/scalacheck/ConsoleReporter.scala b/src/scalacheck/org/scalacheck/ConsoleReporter.scala index c3af6c83a3..93f1dc222e 100644 --- a/src/scalacheck/org/scalacheck/ConsoleReporter.scala +++ b/src/scalacheck/org/scalacheck/ConsoleReporter.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck @@ -37,31 +37,6 @@ object ConsoleReporter { * the given verbosity */ def apply(verbosity: Int = 0) = new ConsoleReporter(verbosity) - @deprecated("(v1.8)", "1.8") - def propReport(s: Int, d: Int) = { - if(d == 0) printf("\rPassed %s tests\r", s) - else printf("\rPassed %s tests; %s discarded\r", s, d) - Console.flush - } - - @deprecated("(v1.8)", "1.8") - def propReport(pName: String, s: Int, d: Int) = { - if(d == 0) printf("\r %s: Passed %s tests\r", pName, s) - else printf("\r %s: Passed %s tests; %s discarded\r", pName, s, d) - Console.flush - } - - @deprecated("(v1.8)", "1.8") - def testReport(res: Test.Result) = { - print(List.fill(78)(' ').mkString) - val s = (if(res.passed) "+ " else "! ") + pretty(res, Params(0)) - printf("\r%s\n", format(s, "", "", 75)) - res - } - - @deprecated("(v1.8)", "1.8") - def testStatsEx(res: Test.Result): Unit = testStatsEx("", res) - def testStatsEx(msg: String, res: Test.Result) = { lazy val m = if(msg.length == 0) "" else msg + ": " res.status match { diff --git a/src/scalacheck/org/scalacheck/Gen.scala b/src/scalacheck/org/scalacheck/Gen.scala index a253b040cd..64bb61c2d3 100644 --- a/src/scalacheck/org/scalacheck/Gen.scala +++ b/src/scalacheck/org/scalacheck/Gen.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck @@ -59,6 +59,12 @@ object Choose { } } +case class FiniteGenRes[+T]( + r: T +) + +sealed trait FiniteGen[+T] extends Gen[FiniteGenRes[T]] + /** Class that represents a generator. */ sealed trait Gen[+T] { @@ -150,13 +156,6 @@ sealed trait Gen[+T] { /** Returns a new property that holds if and only if both this * and the given generator generates the same result, or both - * generators generate no result. - * @deprecated Use <code>==</code> instead */ - @deprecated("Use == instead", "1.7") - def ===[U](g: Gen[U]): Prop = this == g - - /** Returns a new property that holds if and only if both this - * and the given generator generates the same result, or both * generators generate no result. */ def ==[U](g: Gen[U]) = Prop(prms => (this(prms.genPrms), g(prms.genPrms)) match { @@ -221,11 +220,6 @@ object Gen { } } - /* Default generator parameters - * @deprecated Use <code>Gen.Params()</code> instead */ - @deprecated("Use Gen.Params() instead", "1.8") - val defaultParams = Params() - /* Generator factory method */ def apply[T](g: Gen.Params => Option[T]) = new Gen[T] { def apply(p: Gen.Params) = g(p) @@ -310,20 +304,6 @@ object Gen { x <- if(i == 0) g1 else if(i == 1) g2 else gs(i-2) } yield x - /** Chooses one of the given values, with a weighted random distribution. - * @deprecated Use <code>frequency</code> with constant generators - * instead. */ - @deprecated("Use 'frequency' with constant generators instead.", "1.6") - def elementsFreq[T](vs: (Int, T)*): Gen[T] = - frequency(vs.map { case (w,v) => (w, value(v)) } : _*) - - /** A generator that returns a random element from a list - * @deprecated Use <code>oneOf</code> with constant generators instead. */ - @deprecated("Use 'oneOf' with constant generators instead.", "1.6") - def elements[T](xs: T*): Gen[T] = if(xs.isEmpty) fail else for { - i <- choose(0,xs.length-1) - } yield xs(i) - //// List Generators //// @@ -368,12 +348,6 @@ object Gen { * <code>containerOfN[List,T](n,g)</code>. */ def listOfN[T](n: Int, g: Gen[T]) = containerOfN[List,T](n,g) - /** Generates a list of the given length. This method is equal to calling - * <code>containerOfN[List,T](n,g)</code>. - * @deprecated Use the method <code>listOfN</code> instead. */ - @deprecated("Use 'listOfN' instead.", "1.6") - def vectorOf[T](n: Int, g: Gen[T]) = containerOfN[List,T](n,g) - /** A generator that picks a random number of elements from a list */ def someOf[T](l: Iterable[T]) = choose(0,l.size) flatMap (pick(_,l)) @@ -438,16 +412,6 @@ object Gen { //// Number Generators //// - /* Generates positive integers - * @deprecated Use <code>posNum[Int]code> instead */ - @deprecated("Use posNum[Int] instead", "1.7") - def posInt: Gen[Int] = sized(max => choose(1, max)) - - /* Generates negative integers - * @deprecated Use <code>negNum[Int]code> instead */ - @deprecated("Use negNum[Int] instead", "1.7") - def negInt: Gen[Int] = sized(max => choose(-max, -1)) - /** Generates positive numbers of uniform distribution, with an * upper bound of the generation size parameter. */ def posNum[T](implicit num: Numeric[T], c: Choose[T]): Gen[T] = { diff --git a/src/scalacheck/org/scalacheck/Pretty.scala b/src/scalacheck/org/scalacheck/Pretty.scala index f59ac315c7..c40e4aa718 100644 --- a/src/scalacheck/org/scalacheck/Pretty.scala +++ b/src/scalacheck/org/scalacheck/Pretty.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck @@ -49,6 +49,8 @@ object Pretty { implicit def prettyAny(t: Any) = Pretty { p => t.toString } + implicit def prettyString(t: String) = Pretty { p => "\""++t++"\"" } + implicit def prettyList(l: List[Any]) = Pretty { p => l.map("\""+_+"\"").mkString("List(", ", ", ")") } diff --git a/src/scalacheck/org/scalacheck/Prop.scala b/src/scalacheck/org/scalacheck/Prop.scala index 3ae9f22234..dfd85a832a 100644 --- a/src/scalacheck/org/scalacheck/Prop.scala +++ b/src/scalacheck/org/scalacheck/Prop.scala @@ -5,12 +5,13 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck import util.{FreqMap,Buildable} import scala.collection._ +import scala.annotation.tailrec /** A property is a generator that generates a property result */ trait Prop { @@ -102,15 +103,6 @@ trait Prop { } } - /** Returns a new property that holds if and only if both this - * and the given property generates a result with the exact - * same status. Note that this means that if one of the properties is - * proved, and the other one passed, then the resulting property - * will fail. - * @deprecated Use <code>==</code> instead */ - @deprecated("Use == instead.", "1.7") - def ===(p: Prop): Prop = this == p - override def toString = "Prop" /** Put a label on the property to make test reports clearer */ @@ -201,7 +193,7 @@ object Prop { case (_,Undecided) => r case (_,Proof) => merge(this, r, this.status) - case (Proof,_) => merge(this, r, this.status) + case (Proof,_) => merge(this, r, r.status) case (True,True) => merge(this, r, True) } @@ -337,15 +329,12 @@ object Prop { /** A property that depends on the generator size */ def sizedProp(f: Int => Prop): Prop = Prop { prms => + // provedToTrue since if the property is proved for + // one size, it shouldn't be regarded as proved for + // all sizes. provedToTrue(f(prms.genPrms.size)(prms)) } - /** Implication - * @deprecated Use the implication operator of the Prop class instead - */ - @deprecated("Use the implication operator of the Prop class instead", "1.7") - def ==>(b: => Boolean, p: => Prop): Prop = (b: Prop) ==> p - /** Implication with several conditions */ def imply[T](x: T, f: PartialFunction[T,Prop]): Prop = secure(if(f.isDefinedAt(x)) f(x) else undecided) @@ -758,4 +747,17 @@ object Prop { a8: Arbitrary[A8], s8: Shrink[A8], pp8: A8 => Pretty ): Prop = forAll((a: A1) => forAll(f(a, _:A2, _:A3, _:A4, _:A5, _:A6, _:A7, _:A8))) + /** Ensures that the property expression passed in completes within the given space of time. */ + def within(maximumMs: Long)(wrappedProp: => Prop): Prop = new Prop { + @tailrec private def attempt(prms: Params, endTime: Long): Result = { + val result = wrappedProp.apply(prms) + if (System.currentTimeMillis > endTime) { + (if (result.failure) result else Result(False)).label("Timeout") + } else { + if (result.success) result + else attempt(prms, endTime) + } + } + def apply(prms: Params) = attempt(prms, System.currentTimeMillis + maximumMs) + } } diff --git a/src/scalacheck/org/scalacheck/Properties.scala b/src/scalacheck/org/scalacheck/Properties.scala index 8a5b3febc9..26059231d6 100644 --- a/src/scalacheck/org/scalacheck/Properties.scala +++ b/src/scalacheck/org/scalacheck/Properties.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck diff --git a/src/scalacheck/org/scalacheck/Shrink.scala b/src/scalacheck/org/scalacheck/Shrink.scala index a077f21573..ae15bd9616 100644 --- a/src/scalacheck/org/scalacheck/Shrink.scala +++ b/src/scalacheck/org/scalacheck/Shrink.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck diff --git a/src/scalacheck/org/scalacheck/Test.scala b/src/scalacheck/org/scalacheck/Test.scala index 48b0a151a1..4368184823 100644 --- a/src/scalacheck/org/scalacheck/Test.scala +++ b/src/scalacheck/org/scalacheck/Test.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck @@ -19,12 +19,18 @@ object Test { /** Test parameters */ case class Params( minSuccessfulTests: Int = 100, - maxDiscardedTests: Int = 500, + + /** @deprecated Use maxDiscardRatio instead. */ + @deprecated("Use maxDiscardRatio instead.", "1.10") + maxDiscardedTests: Int = -1, + minSize: Int = 0, maxSize: Int = Gen.Params().size, rng: java.util.Random = Gen.Params().rng, workers: Int = 1, - testCallback: TestCallback = new TestCallback {} + testCallback: TestCallback = new TestCallback {}, + maxDiscardRatio: Float = 5, + customClassLoader: Option[ClassLoader] = None ) /** Test statistics */ @@ -90,7 +96,7 @@ object Test { import prms._ if( minSuccessfulTests <= 0 || - maxDiscardedTests < 0 || + maxDiscardRatio <= 0 || minSize < 0 || maxSize < minSize || workers <= 0 @@ -106,12 +112,13 @@ object Test { val names = Set("minSuccessfulTests", "s") val help = "Number of tests that must succeed in order to pass a property" } - object OptMaxDiscarded extends IntOpt { - val default = Test.Params().maxDiscardedTests - val names = Set("maxDiscardedTests", "d") + object OptMaxDiscardRatio extends FloatOpt { + val default = Test.Params().maxDiscardRatio + val names = Set("maxDiscardRatio", "r") val help = - "Number of tests that can be discarded before ScalaCheck stops " + - "testing a property" + "The maximum ratio between discarded and succeeded tests " + + "allowed before ScalaCheck stops testing a property. At " + + "least minSuccessfulTests will always be tested, though." } object OptMinSize extends IntOpt { val default = Test.Params().minSize @@ -135,45 +142,54 @@ object Test { } val opts = Set[Opt[_]]( - OptMinSuccess, OptMaxDiscarded, OptMinSize, + OptMinSuccess, OptMaxDiscardRatio, OptMinSize, OptMaxSize, OptWorkers, OptVerbosity ) def parseParams(args: Array[String]) = parseArgs(args) { optMap => Test.Params( - optMap(OptMinSuccess), - optMap(OptMaxDiscarded), - optMap(OptMinSize), - optMap(OptMaxSize), - Test.Params().rng, - optMap(OptWorkers), - ConsoleReporter(optMap(OptVerbosity)) + minSuccessfulTests = optMap(OptMinSuccess), + maxDiscardRatio = optMap(OptMaxDiscardRatio), + minSize = optMap(OptMinSize), + maxSize = optMap(OptMaxSize), + rng = Test.Params().rng, + workers = optMap(OptWorkers), + testCallback = ConsoleReporter(optMap(OptVerbosity)) ) } } /** Tests a property with the given testing parameters, and returns * the test results. */ - def check(prms: Params, p: Prop): Result = { + def check(params: Params, p: Prop): Result = { + + // maxDiscardedTests is deprecated, but if someone + // uses it let it override maxDiscardRatio + val mdr = + if(params.maxDiscardedTests < 0) params.maxDiscardRatio + else (params.maxDiscardedTests: Float)/(params.minSuccessfulTests: Float) + val prms = params.copy( maxDiscardRatio = mdr) + import prms._ - import actors.Futures.future + import scala.actors.Futures.future assertParams(prms) if(workers > 1) assert(!p.isInstanceOf[Commands], "Commands cannot be checked multi-threaded") - val iterations = minSuccessfulTests / workers - 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 { - var n = 0 - var d = 0 - var size = minSize + (workerdIdx*sizeStep*iterations) + def worker(workerIdx: Int) = future { + params.customClassLoader.map(Thread.currentThread.setContextClassLoader(_)) + var n = 0 // passed tests + var d = 0 // discarded tests 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]]) @@ -184,35 +200,48 @@ object Test { propRes.status match { case Prop.Undecided => d += 1 - testCallback.onPropEval("", workerdIdx, n, d) - if(d >= maxDiscardedTests) res = Result(Exhausted, n, d, fm) + testCallback.onPropEval("", workerIdx, n, d) + // The below condition is kind of hacky. We have to have + // some margin, otherwise workers might stop testing too + // early because they have been exhausted, but the overall + // test has not. + if (n+d > minSuccessfulTests && 1+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) - case Prop.False => res = - Result(Failed(propRes.args, propRes.labels), n, d, fm) - case Prop.Exception(e) => res = - Result(PropException(propRes.args, e, propRes.labels), n, d, fm) + stop = true + case Prop.False => + res = Result(Failed(propRes.args,propRes.labels), n, d, fm) + stop = true + case Prop.Exception(e) => + res = Result(PropException(propRes.args,e,propRes.labels), n, d, fm) + stop = true } } - size += sizeStep } - if(res != null) stop = true - else res = Result(Passed, n, d, fm) - res + if (res == null) { + if (maxDiscardRatio*n > d) Result(Passed, n, d, fm) + else Result(Exhausted, n, d, fm) + } else res } - def mergeResults(r1: () => Result, r2: () => Result) = r1() match { - case Result(Passed, s1, d1, fm1, t) => r2() match { - case Result(Passed, s2, d2, fm2, t) if d1+d2 >= maxDiscardedTests => - () => Result(Exhausted, s1+s2, d1+d2, fm1++fm2, t) - case Result(st, s2, d2, fm2, t) => - () => Result(st, s1+s2, d1+d2, fm1++fm2, t) + def mergeResults(r1: () => Result, r2: () => Result) = { + val Result(st1, s1, d1, fm1, _) = r1() + val Result(st2, s2, d2, fm2, _) = r2() + if (st1 != Passed && st1 != Exhausted) + () => Result(st1, s1+s2, d1+d2, fm1++fm2, 0) + else if (st2 != Passed && st2 != Exhausted) + () => Result(st2, s1+s2, d1+d2, fm1++fm2, 0) + else { + if (s1+s2 >= minSuccessfulTests && maxDiscardRatio*(s1+s2) >= (d1+d2)) + () => Result(Passed, s1+s2, d1+d2, fm1++fm2, 0) + else + () => Result(Exhausted, s1+s2, d1+d2, fm1++fm2, 0) } - case r => () => r } val start = System.currentTimeMillis @@ -237,78 +266,4 @@ object Test { (name,res) } - - // Deprecated methods // - - /** Default testing parameters - * @deprecated Use <code>Test.Params()</code> instead */ - @deprecated("Use Test.Params() instead", "1.8") - val defaultParams = Params() - - /** Property evaluation callback. Takes number of passed and - * discarded tests, respectively */ - @deprecated("(v1.8)", "1.8") - type PropEvalCallback = (Int,Int) => Unit - - /** Property evaluation callback. Takes property name, and number of passed - * and discarded tests, respectively */ - @deprecated("(v1.8)", "1.8") - type NamedPropEvalCallback = (String,Int,Int) => Unit - - /** Test callback. Takes property name, and test results. */ - @deprecated("(v1.8)", "1.8") - type TestResCallback = (String,Result) => Unit - - /** @deprecated (v1.8) Use <code>check(prms.copy(testCallback = myCallback), p)</code> instead. */ - @deprecated("Use check(prms.copy(testCallback = myCallback), p) instead", "1.8") - def check(prms: Params, p: Prop, propCallb: PropEvalCallback): Result = { - val testCallback = new TestCallback { - override def onPropEval(n: String, t: Int, s: Int, d: Int) = propCallb(s,d) - } - check(prms copy (testCallback = testCallback), p) - } - - /** Tests a property and prints results to the console. The - * <code>maxDiscarded</code> parameter specifies how many - * discarded tests that should be allowed before ScalaCheck - * @deprecated (v1.8) Use <code>check(Params(maxDiscardedTests = n, testCallback = ConsoleReporter()), p)</code> instead. */ - @deprecated("Use check(Params(maxDiscardedTests = n, testCallback = ConsoleReporter()), p) instead.", "1.8") - def check(p: Prop, maxDiscarded: Int): Result = - check(Params(maxDiscardedTests = maxDiscarded, testCallback = ConsoleReporter()), p) - - /** Tests a property and prints results to the console - * @deprecated (v1.8) Use <code>check(Params(testCallback = ConsoleReporter()), p)</code> instead. */ - @deprecated("Use check(Params(testCallback = ConsoleReporter()), p) instead.", "1.8") - def check(p: Prop): Result = check(Params(testCallback = ConsoleReporter()), p) - - /** Tests all properties with the given testing parameters, and returns - * the test results. <code>f</code> is a function which is called each - * time a property is evaluted. <code>g</code> is a function called each - * time a property has been fully tested. - * @deprecated (v1.8) Use <code>checkProperties(prms.copy(testCallback = myCallback), ps)</code> instead. */ - @deprecated("Use checkProperties(prms.copy(testCallback = myCallback), ps) instead.", "1.8") - def checkProperties(ps: Properties, prms: Params, - propCallb: NamedPropEvalCallback, testCallb: TestResCallback - ): Seq[(String,Result)] = { - val testCallback = new TestCallback { - override def onPropEval(n: String, t: Int, s: Int, d: Int) = propCallb(n,s,d) - override def onTestResult(n: String, r: Result) = testCallb(n,r) - } - checkProperties(prms copy (testCallback = testCallback), ps) - } - - /** Tests all properties with the given testing parameters, and returns - * the test results. - * @deprecated (v1.8) Use checkProperties(prms, ps) instead */ - @deprecated("Use checkProperties(prms, ps) instead", "1.8") - def checkProperties(ps: Properties, prms: Params): Seq[(String,Result)] = - checkProperties(ps, prms, (n,s,d) => (), (n,s) => ()) - - /** Tests all properties with default testing parameters, and returns - * the test results. The results are also printed on the console during - * testing. - * @deprecated (v1.8) Use <code>checkProperties(Params(), ps)</code> instead. */ - @deprecated("Use checkProperties(Params(), ps) instead.", "1.8") - def checkProperties(ps: Properties): Seq[(String,Result)] = - checkProperties(Params(), ps) } diff --git a/src/scalacheck/org/scalacheck/util/Buildable.scala b/src/scalacheck/org/scalacheck/util/Buildable.scala index 5c960c3ba8..221b8a61c3 100644 --- a/src/scalacheck/org/scalacheck/util/Buildable.scala +++ b/src/scalacheck/org/scalacheck/util/Buildable.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck.util @@ -31,7 +31,7 @@ object Buildable { def builder = (new mutable.ListBuffer[T]).mapResult(_.toStream) } - implicit def buildableArray[T](implicit t: ClassTag[T]) = + implicit def buildableArray[T](implicit cm: ClassTag[T]) = new Buildable[T,Array] { def builder = mutable.ArrayBuilder.make[T] } diff --git a/src/scalacheck/org/scalacheck/util/CmdLineParser.scala b/src/scalacheck/org/scalacheck/util/CmdLineParser.scala index a63e4ba10e..16ac1940b2 100644 --- a/src/scalacheck/org/scalacheck/util/CmdLineParser.scala +++ b/src/scalacheck/org/scalacheck/util/CmdLineParser.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck.util @@ -26,6 +26,7 @@ trait CmdLineParser extends Parsers { } trait Flag extends Opt[Unit] trait IntOpt extends Opt[Int] + trait FloatOpt extends Opt[Float] trait StrOpt extends Opt[String] class OptMap { @@ -68,11 +69,17 @@ trait CmdLineParser extends Parsers { case s if s != null && s.length > 0 && s.forall(_.isDigit) => s.toInt }) + private val floatVal: Parser[Float] = accept("float", { + case s if s != null && s.matches("[0987654321]+\\.?[0987654321]*") + => s.toFloat + }) + private case class OptVal[T](o: Opt[T], v: T) private val optVal: Parser[OptVal[Any]] = opt into { case o: Flag => success(OptVal(o, ())) case o: IntOpt => intVal ^^ (v => OptVal(o, v)) + case o: FloatOpt => floatVal ^^ (v => OptVal(o, v)) case o: StrOpt => strVal ^^ (v => OptVal(o, v)) } diff --git a/src/scalacheck/org/scalacheck/util/FreqMap.scala b/src/scalacheck/org/scalacheck/util/FreqMap.scala index 902c148d67..c7474d3b87 100644 --- a/src/scalacheck/org/scalacheck/util/FreqMap.scala +++ b/src/scalacheck/org/scalacheck/util/FreqMap.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck.util diff --git a/src/scalacheck/org/scalacheck/util/StdRand.scala b/src/scalacheck/org/scalacheck/util/StdRand.scala index 4cc83a4172..317b0ccd10 100644 --- a/src/scalacheck/org/scalacheck/util/StdRand.scala +++ b/src/scalacheck/org/scalacheck/util/StdRand.scala @@ -5,7 +5,7 @@ ** ** ** This software is released under the terms of the Revised BSD License. ** ** There is NO WARRANTY. See the file LICENSE for the full text. ** -\*-------------------------------------------------------------------------*/ +\*------------------------------------------------------------------------ */ package org.scalacheck.util |