diff options
Diffstat (limited to 'src/partest-extras/scala/org/scalacheck/util')
5 files changed, 0 insertions, 356 deletions
diff --git a/src/partest-extras/scala/org/scalacheck/util/Buildable.scala b/src/partest-extras/scala/org/scalacheck/util/Buildable.scala deleted file mode 100644 index 6a275b05c2..0000000000 --- a/src/partest-extras/scala/org/scalacheck/util/Buildable.scala +++ /dev/null @@ -1,77 +0,0 @@ -/*-------------------------------------------------------------------------*\ -** ScalaCheck ** -** Copyright (c) 2007-2014 Rickard Nilsson. All rights reserved. ** -** http://www.scalacheck.org ** -** ** -** 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 - -import collection._ - -trait Buildable[T,C[_]] { - def builder: mutable.Builder[T,C[T]] - def fromIterable(it: Traversable[T]): C[T] = { - val b = builder - b ++= it - b.result() - } -} - -trait Buildable2[T,U,C[_,_]] { - def builder: mutable.Builder[(T,U),C[T,U]] - def fromIterable(it: Traversable[(T,U)]): C[T,U] = { - val b = builder - b ++= it - b.result() - } -} - -object Buildable { - import generic.CanBuildFrom - - implicit def buildableCanBuildFrom[T, C[_]](implicit c: CanBuildFrom[C[_], T, C[T]]) = - new Buildable[T, C] { - def builder = c.apply - } - - import java.util.ArrayList - implicit def buildableArrayList[T] = new Buildable[T,ArrayList] { - def builder = new mutable.Builder[T,ArrayList[T]] { - val al = new ArrayList[T] - def +=(x: T) = { - al.add(x) - this - } - def clear() = al.clear() - def result() = al - } - } - -} - -object Buildable2 { - - implicit def buildableMutableMap[T,U] = new Buildable2[T,U,mutable.Map] { - def builder = mutable.Map.newBuilder - } - - implicit def buildableImmutableMap[T,U] = new Buildable2[T,U,immutable.Map] { - def builder = immutable.Map.newBuilder - } - - implicit def buildableMap[T,U] = new Buildable2[T,U,Map] { - def builder = Map.newBuilder - } - - implicit def buildableImmutableSortedMap[T: Ordering, U] = new Buildable2[T,U,immutable.SortedMap] { - def builder = immutable.SortedMap.newBuilder - } - - implicit def buildableSortedMap[T: Ordering, U] = new Buildable2[T,U,SortedMap] { - def builder = SortedMap.newBuilder - } - -} diff --git a/src/partest-extras/scala/org/scalacheck/util/CmdLineParser.scala b/src/partest-extras/scala/org/scalacheck/util/CmdLineParser.scala deleted file mode 100644 index 45b6ac6948..0000000000 --- a/src/partest-extras/scala/org/scalacheck/util/CmdLineParser.scala +++ /dev/null @@ -1,41 +0,0 @@ -/*-------------------------------------------------------------------------*\ -** ScalaCheck ** -** Copyright (c) 2007-2014 Rickard Nilsson. All rights reserved. ** -** http://www.scalacheck.org ** -** ** -** 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 - -import scala.collection.Set -import org.scalacheck.Test - -private[scalacheck] trait CmdLineParser { - - type Elem = String - - trait Opt[+T] { - val default: T - val names: Set[String] - val help: String - } - trait Flag extends Opt[Unit] - trait IntOpt extends Opt[Int] - trait FloatOpt extends Opt[Float] - trait StrOpt extends Opt[String] - - class OptMap { - private val opts = new collection.mutable.HashMap[Opt[_], Any] - def apply(flag: Flag): Boolean = opts.contains(flag) - def apply[T](opt: Opt[T]): T = opts.get(opt) match { - case None => opt.default - case Some(v) => v.asInstanceOf[T] - } - def update[T](opt: Opt[T], optVal: T) = opts.update(opt, optVal) - } - - val opts: Set[Opt[_]] - -} diff --git a/src/partest-extras/scala/org/scalacheck/util/ConsoleReporter.scala b/src/partest-extras/scala/org/scalacheck/util/ConsoleReporter.scala deleted file mode 100644 index 89858dfb64..0000000000 --- a/src/partest-extras/scala/org/scalacheck/util/ConsoleReporter.scala +++ /dev/null @@ -1,44 +0,0 @@ -/*-------------------------------------------------------------------------*\ -** ScalaCheck ** -** Copyright (c) 2007-2014 Rickard Nilsson. All rights reserved. ** -** http://www.scalacheck.org ** -** ** -** 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 - -import Pretty.{Params, pretty, format} -import org.scalacheck.{Prop, Properties, Test} - -/** A [[org.scalacheck.Test.TestCallback]] implementation that prints - * test results directly to the console. This is the callback used - * by ScalaCheck's command line test runner, and when you run [[org.scalacheck.Prop!.check:Unit*]] - */ -class ConsoleReporter(val verbosity: Int) extends Test.TestCallback { - - private val prettyPrms = Params(verbosity) - - override def onTestResult(name: String, res: Test.Result) = { - if(verbosity > 0) { - if(name == "") { - val s = (if(res.passed) "+ " else "! ") + pretty(res, prettyPrms) - printf("\r%s\n", format(s, "", "", 75)) - } else { - val s = (if(res.passed) "+ " else "! ") + name + ": " + - pretty(res, prettyPrms) - printf("\r%s\n", format(s, "", "", 75)) - } - } - } - -} - -object ConsoleReporter { - - /** Factory method, creates a ConsoleReporter with the - * the given verbosity */ - def apply(verbosity: Int = 0) = new ConsoleReporter(verbosity) - -} diff --git a/src/partest-extras/scala/org/scalacheck/util/FreqMap.scala b/src/partest-extras/scala/org/scalacheck/util/FreqMap.scala deleted file mode 100644 index 2a9f36f1e5..0000000000 --- a/src/partest-extras/scala/org/scalacheck/util/FreqMap.scala +++ /dev/null @@ -1,65 +0,0 @@ -/*-------------------------------------------------------------------------*\ -** ScalaCheck ** -** Copyright (c) 2007-2014 Rickard Nilsson. All rights reserved. ** -** http://www.scalacheck.org ** -** ** -** 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 - -trait FreqMap[T] { - protected val underlying: scala.collection.immutable.Map[T,Int] - val total: Int - - def +(t: T) = new FreqMap[T] { - private val n = FreqMap.this.underlying.get(t) match { - case None => 1 - case Some(n) => n+1 - } - val underlying = FreqMap.this.underlying + (t -> n) - val total = FreqMap.this.total + 1 - } - - def -(t: T) = new FreqMap[T] { - val underlying = FreqMap.this.underlying.get(t) match { - case None => FreqMap.this.underlying - case Some(n) => FreqMap.this.underlying + (t -> (n-1)) - } - val total = FreqMap.this.total + 1 - } - - def ++(fm: FreqMap[T]) = new FreqMap[T] { - private val keys = FreqMap.this.underlying.keySet ++ fm.underlying.keySet - private val mappings = keys.toStream.map { x => - (x, fm.getCount(x).getOrElse(0) + FreqMap.this.getCount(x).getOrElse(0)) - } - val underlying = scala.collection.immutable.Map(mappings: _*) - val total = FreqMap.this.total + fm.total - } - - def --(fm: FreqMap[T]) = new FreqMap[T] { - val underlying = FreqMap.this.underlying transform { - case (x,n) => n - fm.getCount(x).getOrElse(0) - } - lazy val total = (0 /: underlying.valuesIterator) (_ + _) - } - - def getCount(t: T) = underlying.get(t) - - def getCounts: List[(T,Int)] = underlying.toList.sortBy(-_._2) - - def getRatio(t: T) = for(c <- getCount(t)) yield (c: Float)/total - - def getRatios = for((t,c) <- getCounts) yield (t, (c: Float)/total) - - override def toString = underlying.toString -} - -object FreqMap { - def empty[T] = new FreqMap[T] { - val underlying = scala.collection.immutable.Map.empty[T,Int] - val total = 0 - } -} diff --git a/src/partest-extras/scala/org/scalacheck/util/Pretty.scala b/src/partest-extras/scala/org/scalacheck/util/Pretty.scala deleted file mode 100644 index 13a1b44b51..0000000000 --- a/src/partest-extras/scala/org/scalacheck/util/Pretty.scala +++ /dev/null @@ -1,129 +0,0 @@ -/*-------------------------------------------------------------------------*\ -** ScalaCheck ** -** Copyright (c) 2007-2014 Rickard Nilsson. All rights reserved. ** -** http://www.scalacheck.org ** -** ** -** 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 - -import org.scalacheck.Prop.Arg -import org.scalacheck.Test - -import math.round - - -sealed trait Pretty { - def apply(prms: Pretty.Params): String - - def map(f: String => String) = Pretty(prms => f(Pretty.this(prms))) - - def flatMap(f: String => Pretty) = Pretty(prms => f(Pretty.this(prms))(prms)) -} - -object Pretty { - - case class Params(verbosity: Int) - - val defaultParams = Params(0) - - def apply(f: Params => String) = new Pretty { def apply(p: Params) = f(p) } - - def pretty[T <% Pretty](t: T, prms: Params): String = t(prms) - - def pretty[T <% Pretty](t: T): String = t(defaultParams) - - implicit def strBreak(s1: String) = new { - def /(s2: String) = if(s2 == "") s1 else s1+"\n"+s2 - } - - def pad(s: String, c: Char, length: Int) = - if(s.length >= length) s - else s + List.fill(length-s.length)(c).mkString - - def break(s: String, lead: String, length: Int): String = - if(s.length <= length) s - else s.substring(0, length) / break(lead+s.substring(length), lead, length) - - def format(s: String, lead: String, trail: String, width: Int) = - s.lines.map(l => break(lead+l+trail, " ", width)).mkString("\n") - - 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(", ", ", ")") - } - - implicit def prettyThrowable(e: Throwable) = Pretty { prms => - val strs = e.getStackTrace.map { st => - import st._ - getClassName+"."+getMethodName + "("+getFileName+":"+getLineNumber+")" - } - - val strs2 = - if(prms.verbosity <= 0) Array[String]() - else if(prms.verbosity <= 1) strs.take(5) - else strs - - e.getClass.getName + ": " + e.getMessage / strs2.mkString("\n") - } - - def prettyArgs(args: Seq[Arg[Any]]): Pretty = Pretty { prms => - if(args.isEmpty) "" else { - for((a,i) <- args.zipWithIndex) yield { - val l = "> "+(if(a.label == "") "ARG_"+i else a.label) - val s = - if(a.shrinks == 0) "" - else "\n"+l+"_ORIGINAL: "+a.prettyOrigArg(prms) - l+": "+a.prettyArg(prms)+""+s - } - }.mkString("\n") - } - - implicit def prettyFreqMap(fm: FreqMap[Set[Any]]) = Pretty { prms => - if(fm.total == 0) "" - else { - "> Collected test data: " / { - for { - (xs,r) <- fm.getRatios - ys = xs - (()) - if !ys.isEmpty - } yield round(r*100)+"% " + ys.mkString(", ") - }.mkString("\n") - } - } - - implicit def prettyTestRes(res: Test.Result) = Pretty { prms => - def labels(ls: collection.immutable.Set[String]) = - if(ls.isEmpty) "" - else "> Labels of failing property: " / ls.mkString("\n") - val s = res.status match { - case Test.Proved(args) => "OK, proved property."/prettyArgs(args)(prms) - case Test.Passed => "OK, passed "+res.succeeded+" tests." - case Test.Failed(args, l) => - "Falsified after "+res.succeeded+" passed tests."/labels(l)/prettyArgs(args)(prms) - case Test.Exhausted => - "Gave up after only "+res.succeeded+" passed tests. " + - res.discarded+" tests were discarded." - case Test.PropException(args,e,l) => - "Exception raised on property evaluation."/labels(l)/prettyArgs(args)(prms)/ - "> Exception: "+pretty(e,prms) - case Test.GenException(e) => - "Exception raised on argument generation."/ - "> Exception: "+pretty(e,prms) - } - val t = if(prms.verbosity <= 1) "" else "Elapsed time: "+prettyTime(res.time) - s/t/pretty(res.freqMap,prms) - } - - def prettyTime(millis: Long): String = { - val min = millis/(60*1000) - val sec = (millis-(60*1000*min)) / 1000d - if(min <= 0) "%.3f sec ".format(sec) - else "%d min %.3f sec ".format(min, sec) - } -} |