diff options
-rw-r--r-- | build.sbt | 27 | ||||
-rw-r--r-- | project/PartestUtil.scala | 2 | ||||
-rwxr-xr-x | scripts/jobs/integrate/bootstrap | 6 | ||||
-rwxr-xr-x | scripts/jobs/validate/test | 2 | ||||
-rw-r--r-- | test/files/scalacheck/MutableTreeMap.scala | 345 | ||||
-rw-r--r-- | test/files/scalacheck/MutableTreeSet.scala | 216 | ||||
-rw-r--r-- | test/files/scalacheck/parallel-collections/pc.scala | 71 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/Test.scala | 19 | ||||
-rw-r--r-- | test/files/scalacheck/redblacktree.scala | 258 | ||||
-rw-r--r-- | test/files/scalacheck/test.scala | 8 | ||||
-rw-r--r-- | test/files/scalacheck/testdir/dep.scala | 7 | ||||
-rw-r--r-- | test/files/scalacheck/testdir/test.scala | 10 | ||||
-rw-r--r-- | test/scalacheck/CheckCollections.scala (renamed from test/files/scalacheck/CheckCollections.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/CheckEither.scala (renamed from test/files/scalacheck/CheckEither.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/Ctrie.scala (renamed from test/files/scalacheck/Ctrie.scala) | 5 | ||||
-rw-r--r-- | test/scalacheck/MutablePriorityQueue.scala (renamed from test/files/scalacheck/MutablePriorityQueue.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/MutableTreeMap.scala | 337 | ||||
-rw-r--r-- | test/scalacheck/MutableTreeSet.scala | 209 | ||||
-rw-r--r-- | test/scalacheck/ReflectionExtractors.scala (renamed from test/files/scalacheck/ReflectionExtractors.scala) | 4 | ||||
-rw-r--r-- | test/scalacheck/Unrolled.scala (renamed from test/files/scalacheck/Unrolled.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/array-new.scala (renamed from test/files/scalacheck/array-new.scala) | 4 | ||||
-rw-r--r-- | test/scalacheck/array-old.scala (renamed from test/files/scalacheck/array-old.scala) | 2 | ||||
-rwxr-xr-x | test/scalacheck/concurrent-map.scala (renamed from test/files/scalacheck/concurrent-map.scala) | 14 | ||||
-rw-r--r-- | test/scalacheck/duration.scala (renamed from test/files/scalacheck/duration.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/list.scala (renamed from test/files/scalacheck/list.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/nan-ordering.scala (renamed from test/files/scalacheck/nan-ordering.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/IntOperators.scala (renamed from test/files/scalacheck/parallel-collections/IntOperators.scala) | 19 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/IntValues.scala (renamed from test/files/scalacheck/parallel-collections/IntValues.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/Operators.scala (renamed from test/files/scalacheck/parallel-collections/Operators.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/PairOperators.scala (renamed from test/files/scalacheck/parallel-collections/PairOperators.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/PairValues.scala (renamed from test/files/scalacheck/parallel-collections/PairValues.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelArrayCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelArrayCheck.scala) | 12 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelArrayTest.scala (renamed from test/files/scalacheck/parallel-collections/ParallelArrayTest.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelArrayViewCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelArrayViewCheck.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelCtrieCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelHashMapCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelHashMapCheck.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelHashSetCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelHashSetCheck.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelHashTrieCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelHashTrieCheck.scala) | 4 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelIterableCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelMapCheck1.scala (renamed from test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelRangeCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelRangeCheck.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelSeqCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelSetCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelSetCheck.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/ParallelVectorCheck.scala (renamed from test/files/scalacheck/parallel-collections/ParallelVectorCheck.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/parallel-collections/pc.scala | 61 | ||||
-rw-r--r-- | test/scalacheck/primitive-eqeq.scala (renamed from test/files/scalacheck/primitive-eqeq.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/ArbitraryTreesAndNames.scala (renamed from test/files/scalacheck/quasiquotes/ArbitraryTreesAndNames.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/DefinitionConstructionProps.scala (renamed from test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala (renamed from test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/DeprecationProps.scala (renamed from test/files/scalacheck/quasiquotes/DeprecationProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/ErrorProps.scala (renamed from test/files/scalacheck/quasiquotes/ErrorProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/ForProps.scala (renamed from test/files/scalacheck/quasiquotes/ForProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/LiftableProps.scala (renamed from test/files/scalacheck/quasiquotes/LiftableProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/PatternConstructionProps.scala (renamed from test/files/scalacheck/quasiquotes/PatternConstructionProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/PatternDeconstructionProps.scala (renamed from test/files/scalacheck/quasiquotes/PatternDeconstructionProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/QuasiquoteProperties.scala (renamed from test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/RuntimeErrorProps.scala (renamed from test/files/scalacheck/quasiquotes/RuntimeErrorProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/TermConstructionProps.scala (renamed from test/files/scalacheck/quasiquotes/TermConstructionProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/TermDeconstructionProps.scala (renamed from test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/TypeConstructionProps.scala (renamed from test/files/scalacheck/quasiquotes/TypeConstructionProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/TypeDeconstructionProps.scala (renamed from test/files/scalacheck/quasiquotes/TypeDeconstructionProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/TypecheckedProps.scala (renamed from test/files/scalacheck/quasiquotes/TypecheckedProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/quasiquotes/UnliftableProps.scala (renamed from test/files/scalacheck/quasiquotes/UnliftableProps.scala) | 0 | ||||
-rw-r--r-- | test/scalacheck/range.scala (renamed from test/files/scalacheck/range.scala) | 10 | ||||
-rw-r--r-- | test/scalacheck/redblacktree.scala | 247 | ||||
-rw-r--r-- | test/scalacheck/scaladoc/CommentFactoryTest.scala (renamed from test/scaladoc/scalacheck/CommentFactoryTest.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/scaladoc/HtmlFactoryTest.scala (renamed from test/scaladoc/scalacheck/HtmlFactoryTest.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/scaladoc/IndexScriptTest.scala (renamed from test/scaladoc/scalacheck/IndexScriptTest.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/scan.scala (renamed from test/files/scalacheck/scan.scala) | 5 | ||||
-rw-r--r-- | test/scalacheck/substringTests.scala (renamed from test/files/scalacheck/substringTests.scala) | 3 | ||||
-rw-r--r-- | test/scalacheck/t2460.scala (renamed from test/files/scalacheck/t2460.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/t4147.scala (renamed from test/files/scalacheck/t4147.scala) | 2 | ||||
-rw-r--r-- | test/scalacheck/treemap.scala (renamed from test/files/scalacheck/treemap.scala) | 4 | ||||
-rw-r--r-- | test/scalacheck/treeset.scala (renamed from test/files/scalacheck/treeset.scala) | 4 | ||||
-rw-r--r-- | test/scaladoc/scalacheck/HtmlFactoryTest.flags | 1 | ||||
-rw-r--r-- | versions.properties | 2 |
76 files changed, 917 insertions, 1039 deletions
@@ -3,7 +3,7 @@ * * What you see below is very much work-in-progress. The following features are implemented: * - Compiling all classses for the compiler and library ("compile" in the respective subprojects) - * - Running JUnit tests ("test") and partest ("test/it:test") + * - Running JUnit ("junit/test"), ScalaCheck ("scalacheck/test"), and partest ("test/it:test") tests * - Creating build/quick with all compiled classes and launcher scripts ("dist/mkQuick") * - Creating build/pack with all JARs and launcher scripts ("dist/mkPack") * - Building all scaladoc sets ("doc") @@ -39,11 +39,11 @@ val scalaSwingDep = scalaDep("org.scala-lang.modules", "scala-swi val scalaXmlDep = scalaDep("org.scala-lang.modules", "scala-xml") val scalaParserCombinatorsDep = scalaDep("org.scala-lang.modules", "scala-parser-combinators") val partestDep = scalaDep("org.scala-lang.modules", "scala-partest", versionProp = "partest") -val scalacheckDep = scalaDep("org.scalacheck", "scalacheck", scope = "it") // Non-Scala dependencies: val junitDep = "junit" % "junit" % "4.11" val junitInterfaceDep = "com.novocode" % "junit-interface" % "0.11" % "test" +val scalacheckDep = "org.scalacheck" % "scalacheck_2.12" % "1.13.4" % "test" val jolDep = "org.openjdk.jol" % "jol-core" % "0.5" val asmDep = "org.scala-lang.modules" % "scala-asm" % versionProps("scala-asm.version") val jlineDep = "jline" % "jline" % versionProps("jline.version") @@ -567,7 +567,20 @@ lazy val junit = project.in(file("test") / "junit") javaOptions in Test += "-Xss1M", libraryDependencies ++= Seq(junitDep, junitInterfaceDep, jolDep), testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v"), - // testFrameworks -= new TestFramework("org.scalacheck.ScalaCheckFramework"), + unmanagedSourceDirectories in Compile := Nil, + unmanagedSourceDirectories in Test := List(baseDirectory.value) + ) + +lazy val scalacheck = project.in(file("test") / "scalacheck") + .dependsOn(library, reflect, compiler, scaladoc) + .settings(clearSourceAndResourceDirectories) + .settings(commonSettings) + .settings(disableDocs) + .settings(disablePublishing) + .settings( + fork in Test := true, + javaOptions in Test += "-Xss1M", + libraryDependencies ++= Seq(scalacheckDep), unmanagedSourceDirectories in Compile := Nil, unmanagedSourceDirectories in Test := List(baseDirectory.value) ) @@ -647,7 +660,7 @@ lazy val test = project .settings(disablePublishing) .settings(Defaults.itSettings) .settings( - libraryDependencies ++= Seq(asmDep, partestDep, scalaXmlDep, scalacheckDep), + libraryDependencies ++= Seq(asmDep, partestDep, scalaXmlDep), libraryDependencies ++= { // Resolve the JARs for all test/files/lib/*.jar.desired.sha1 files through Ivy val baseDir = (baseDirectory in ThisBuild).value @@ -664,7 +677,6 @@ lazy val test = project fork in IntegrationTest := true, javaOptions in IntegrationTest += "-Xmx2G", testFrameworks += new TestFramework("scala.tools.partest.sbt.Framework"), - // testFrameworks -= new TestFramework("org.scalacheck.ScalaCheckFramework"), testOptions in IntegrationTest += Tests.Argument("-Dpartest.java_opts=-Xmx1024M -Xms64M"), testOptions in IntegrationTest += Tests.Argument("-Dpartest.scalac_opts=" + (scalacOptions in Compile).value.mkString(" ")), testOptions in IntegrationTest += Tests.Setup { () => @@ -796,9 +808,10 @@ lazy val root: Project = (project in file(".")) testAll := { val results = ScriptCommands.sequence[Result[Unit]](List( (Keys.test in Test in junit).result, + (Keys.test in Test in scalacheck).result, (testOnly in IntegrationTest in testP).toTask(" -- run").result, (testOnly in IntegrationTest in testP).toTask(" -- pos neg jvm").result, - (testOnly in IntegrationTest in testP).toTask(" -- res scalap specialized scalacheck").result, + (testOnly in IntegrationTest in testP).toTask(" -- res scalap specialized").result, (testOnly in IntegrationTest in testP).toTask(" -- instrumented presentation").result, (testOnly in IntegrationTest in testP).toTask(" -- --srcpath scaladoc").result, (Keys.test in Test in osgiTestFelix).result, @@ -817,7 +830,7 @@ lazy val root: Project = (project in file(".")) "junit/test", "partest run", "partest pos neg jvm", - "partest res scalap specialized scalacheck", + "partest res scalap specialized", "partest instrumented presentation", "partest --srcpath scaladoc", "osgiTestFelix/test", diff --git a/project/PartestUtil.scala b/project/PartestUtil.scala index 7cb9af4c94..7343c1857f 100644 --- a/project/PartestUtil.scala +++ b/project/PartestUtil.scala @@ -28,7 +28,7 @@ object PartestUtil { def partestParser(globalBase: File, testBase: File): Parser[String] = { val knownUnaryOptions = List( "--pos", "--neg", "--run", "--jvm", "--res", "--ant", "--scalap", "--specialized", - "--scalacheck", "--instrumented", "--presentation", "--failed", "--update-check", + "--instrumented", "--presentation", "--failed", "--update-check", "--show-diff", "--show-log", "--verbose", "--terse", "--debug", "--version", "--self-test", "--help") val srcPathOption = "--srcpath" val grepOption = "--grep" diff --git a/scripts/jobs/integrate/bootstrap b/scripts/jobs/integrate/bootstrap index 7c045ae918..3933854e4f 100755 --- a/scripts/jobs/integrate/bootstrap +++ b/scripts/jobs/integrate/bootstrap @@ -250,7 +250,7 @@ buildSwing() { } # should only be called with publishTasks publishing to private-repo -buildScalacheck(){ +buildScalaCheck(){ if [ "$SCALACHECK_BUILT" != "yes" ] && [ "$forceRebuild" != "yes" ] && ( sbtResolve "org.scalacheck" "scalacheck" $SCALACHECK_VER ) then echo "Found scalacheck $SCALACHECK_VER; not building." else @@ -261,14 +261,14 @@ buildScalacheck(){ fi } -# build modules, using ${buildTasks[@]} (except for Scalacheck, which is hard-coded to publish to private-repo) +# build modules, using ${buildTasks[@]} (except for ScalaCheck, which is hard-coded to publish to private-repo) buildModules() { publishTasks=('set credentials += Credentials(Path.userHome / ".credentials-private-repo")' "set every publishTo := Some(\"private-repo\" at \"$releaseTempRepoUrl\")") buildTasks=($publishPrivateTask) buildXML buildParsers buildSwing - # buildScalacheck + # buildScalaCheck buildPartest } diff --git a/scripts/jobs/validate/test b/scripts/jobs/validate/test index 7b00356390..39fafebaef 100755 --- a/scripts/jobs/validate/test +++ b/scripts/jobs/validate/test @@ -17,7 +17,7 @@ case $prDryRun in # build quick using STARR built upstream, as specified by scalaVersion # (in that sense it's locker, since it was built with starr by that upstream job); - # and run JUnit tests, partest, OSGi tests, MiMa and scaladoc + # and run JUnit tests, ScalaCheck tests, partest, OSGi tests, MiMa and scaladoc $SBT \ -Dstarr.version=$scalaVersion \ --warn \ diff --git a/test/files/scalacheck/MutableTreeMap.scala b/test/files/scalacheck/MutableTreeMap.scala deleted file mode 100644 index 42b88c56a7..0000000000 --- a/test/files/scalacheck/MutableTreeMap.scala +++ /dev/null @@ -1,345 +0,0 @@ -import java.io._ - -import org.scalacheck._ -import org.scalacheck.Arbitrary._ -import org.scalacheck.Prop.forAll - -import scala.collection.generic.CanBuildFrom -import scala.collection.immutable -import scala.collection.mutable -import scala.util.Try -import scala.collection.mutable.{RedBlackTree => RB} - -package scala.collection.mutable { - - trait Generators { - - def genRedBlackTree[A: Arbitrary: Ordering, B: Arbitrary]: Gen[RB.Tree[A, B]] = { - import org.scalacheck.Gen._ - for { entries <- listOf(arbitrary[(A, B)]) } yield { - val tree = RB.Tree.empty[A, B] - entries.foreach { case (k, v) => RB.insert(tree, k, v) } - tree - } - } - - // Note: in scalacheck 1.12.2 tree maps can be automatically generated without the need for custom - // machinery - def genTreeMap[A: Arbitrary: Ordering, B: Arbitrary]: Gen[mutable.TreeMap[A, B]] = { - import org.scalacheck.Gen._ - for { - keys <- listOf(arbitrary[A]) - values <- listOfN(keys.size, arbitrary[B]) - } yield mutable.TreeMap(keys zip values: _*) - } - - implicit def arbRedBlackTree[A: Arbitrary: Ordering, B: Arbitrary] = Arbitrary(genRedBlackTree[A, B]) - implicit def arbTreeMap[A: Arbitrary: Ordering, B: Arbitrary] = Arbitrary(genTreeMap[A, B]) - } - - object RedBlackTreeProperties extends Properties("mutable.RedBlackTree") with Generators { - type K = String - type V = Int - - property("initial invariants") = forAll { (tree: RB.Tree[K, V]) => - RB.isValid(tree) - } - - property("insert") = forAll { (tree: RB.Tree[K, V], entries: Seq[(K, V)]) => - entries.foreach { case (k, v) => RB.insert(tree, k, v) } - RB.isValid(tree) && entries.toMap.forall { case (k, v) => RB.get(tree, k) == Some(v) } - } - - property("delete") = forAll { (tree: RB.Tree[K, V], ks: Seq[K]) => - ks.foreach { k => RB.delete(tree, k) } - RB.isValid(tree) && ks.toSet.forall { k => RB.get(tree, k) == None } - } - - property("insert & delete") = forAll { (tree: RB.Tree[K, V], ops: Seq[Either[(K, V), K]]) => - ops.foreach { - case Left((k, v)) => RB.insert(tree, k, v) - case Right(k) => RB.delete(tree, k) - } - RB.isValid(tree) - } - - property("min") = forAll { (entries: Seq[(K, V)]) => - val tree = RB.Tree.empty[K, V] - entries.foreach { case (k, v) => RB.insert(tree, k, v) } - RB.min(tree) == (if (entries.isEmpty) None else Some(entries.toMap.min)) - } - - property("max") = forAll { (entries: Seq[(K, V)]) => - val tree = RB.Tree.empty[K, V] - entries.foreach { case (k, v) => RB.insert(tree, k, v) } - RB.max(tree) == (if (entries.isEmpty) None else Some(entries.toMap.max)) - } - } - - object MutableTreeMapProperties extends Properties("mutable.TreeMap") with Generators { - type K = String - type V = Int - - property("get, contains") = forAll { (allEntries: Map[K, V]) => - val entries = allEntries.take(allEntries.size / 2) - - val map = mutable.TreeMap[K, V]() - map ++= entries - - allEntries.forall { case (k, v) => - map.contains(k) == entries.contains(k) && - map.get(k) == entries.get(k) - } - } - - property("size, isEmpty") = forAll { (entries: Map[K, V]) => - val map = mutable.TreeMap[K, V]() - map ++= entries - map.size == entries.size && map.isEmpty == entries.isEmpty - } - - property("+=") = forAll { (map: mutable.TreeMap[K, V], k: K, v: V) => - val oldSize = map.size - val containedKeyBefore = map.contains(k) - val newExpectedSize = if(containedKeyBefore) oldSize else oldSize + 1 - - map += (k -> v) - map.contains(k) && map.get(k) == Some(v) && map.size == newExpectedSize - } - - property("++=") = forAll { (map: mutable.TreeMap[K, V], entries: Seq[(K, V)]) => - val oldEntries = map.toMap - map ++= entries - (oldEntries ++ entries).forall { case (k, v) => map.get(k) == Some(v) } - } - - property("-=") = forAll { (map: mutable.TreeMap[K, V], k: K) => - val oldSize = map.size - val containedKeyBefore = map.contains(k) - val newExpectedSize = if(containedKeyBefore) oldSize - 1 else oldSize - - map -= k - !map.contains(k) && map.get(k) == None && map.size == newExpectedSize - } - - property("--=") = forAll { (map: mutable.TreeMap[K, V], ks: Seq[K]) => - val oldElems = map.toList - map --= ks - val deletedElems = ks.toSet - oldElems.forall { case (k, v) => map.get(k) == (if(deletedElems(k)) None else Some(v)) } - } - - property("iterator") = forAll { (entries: Map[K, V]) => - val map = mutable.TreeMap[K, V]() - map ++= entries - - map.iterator.toSeq == entries.toSeq.sorted - } - - property("iteratorFrom") = forAll { (entries: Map[K, V], k: K) => - val map = mutable.TreeMap[K, V]() - map ++= entries - - map.iteratorFrom(k).toSeq == entries.filterKeys(_ >= k).toSeq.sorted - } - - property("keysIteratorFrom") = forAll { (entries: Map[K, V], k: K) => - val map = mutable.TreeMap[K, V]() - map ++= entries - - map.keysIteratorFrom(k).toSeq == entries.keysIterator.filter(_ >= k).toSeq.sorted - } - - property("valuesIteratorFrom") = forAll { (entries: Map[K, V], k: K) => - val map = mutable.TreeMap[K, V]() - map ++= entries - - map.valuesIteratorFrom(k).toSeq == entries.filterKeys(_ >= k).toSeq.sorted.map(_._2) - } - - property("headOption") = forAll { (map: mutable.TreeMap[K, V]) => - map.headOption == Try(map.iterator.next()).toOption - } - - property("lastOption") = forAll { (map: mutable.TreeMap[K, V]) => - map.lastOption == Try(map.iterator.max).toOption - } - - property("clear") = forAll { (map: mutable.TreeMap[K, V]) => - map.clear() - map.isEmpty && map.size == 0 - } - - property("serializable") = forAll { (map: mutable.TreeMap[K, V]) => - val bytesOut = new ByteArrayOutputStream() - val out = new ObjectOutputStream(bytesOut) - out.writeObject(map) - val bytes = bytesOut.toByteArray - - val in = new ObjectInputStream(new ByteArrayInputStream(bytes)) - val sameMap = in.readObject().asInstanceOf[mutable.TreeMap[K, V]] - map.iterator.toSeq == sameMap.iterator.toSeq - } - - property("same behavior as immutable.TreeMap") = forAll { ops: Seq[Either[(K, V), K]] => - var imap = immutable.TreeMap[K, V]() - val mmap = mutable.TreeMap[K, V]() - - ops.foreach { - case Left((k, v)) => imap += k -> v; mmap += k -> v - case Right(k) => imap -= k; mmap -= k - } - - imap.toList == mmap.toList - } - } - - object MutableTreeMapViewProperties extends Properties("mutable.TreeMapView") with Generators { - type K = String - type V = Int - - implicit val ord = implicitly[Ordering[K]] - - def in(key: K, from: Option[K], until: Option[K]) = - from.fold(true)(_ <= key) && until.fold(true)(_ > key) - - def entriesInView[This <: TraversableOnce[(K, V)], That](entries: This, from: Option[K], until: Option[K])(implicit bf: CanBuildFrom[This, (K, V), That]) = { - (bf.apply(entries) ++= entries.filter { case (k, _) => in(k, from, until) }).result() - } - - property("get, contains") = forAll { (allEntries: Map[K, V], from: Option[K], until: Option[K]) => - val entries = allEntries.take(allEntries.size / 2) - - val map = mutable.TreeMap[K, V]() - map ++= entries - - val mapView = map.rangeImpl(from, until) - allEntries.forall { case (k, v) => - mapView.contains(k) == (in(k, from, until) && entries.contains(k)) && - mapView.get(k) == (if(in(k, from, until)) entries.get(k) else None) - } - } - - property("size, isEmpty") = forAll { (entries: Map[K, V], from: Option[K], until: Option[K]) => - val map = mutable.TreeMap[K, V]() - map ++= entries - - val mapView = map.rangeImpl(from, until) - mapView.size == entriesInView(entries, from, until).size && - mapView.isEmpty == !entries.exists { kv => in(kv._1, from, until) } - } - - property("+=") = forAll { (map: mutable.TreeMap[K, V], k: K, v: V, from: Option[K], until: Option[K]) => - val oldSize = map.size - val containedKeyBefore = map.contains(k) - val newExpectedSize = if(containedKeyBefore) oldSize else oldSize + 1 - val isInRange = in(k, from, until) - - val mapView = map.rangeImpl(from, until) - mapView += (k -> v) - - map.contains(k) && map.get(k) == Some(v) && map.size == newExpectedSize && - mapView.contains(k) == isInRange && - mapView.get(k) == (if(isInRange) Some(v) else None) - } - - property("++=") = forAll { (map: mutable.TreeMap[K, V], entries: Seq[(K, V)], from: Option[K], until: Option[K]) => - val mapView = map.rangeImpl(from, until) - mapView ++= entries - entries.toMap.forall { case (k, v) => - map.get(k) == Some(v) && - mapView.get(k) == (if (in(k, from, until)) Some(v) else None) - } - } - - property("-=") = forAll { (map: mutable.TreeMap[K, V], k: K, from: Option[K], until: Option[K]) => - val oldSize = map.size - val containedKeyBefore = map.contains(k) - val newExpectedSize = if(containedKeyBefore) oldSize - 1 else oldSize - - val mapView = map.rangeImpl(from, until) - mapView -= k - - !map.contains(k) && map.get(k) == None && map.size == newExpectedSize && - !mapView.contains(k) && - mapView.get(k) == None - } - - property("--=") = forAll { (map: mutable.TreeMap[K, V], ks: Seq[K], from: Option[K], until: Option[K]) => - val mapView = map.rangeImpl(from, until) - mapView --= ks - ks.toSet.forall { k => map.get(k) == None && mapView.get(k) == None } - } - - property("iterator") = forAll { (entries: Map[K, V], from: Option[K], until: Option[K]) => - val map = mutable.TreeMap[K, V]() - map ++= entries - - val mapView = map.rangeImpl(from, until) - mapView.iterator.toSeq == entriesInView(entries, from, until).toSeq.sorted - } - - property("iteratorFrom") = forAll { (entries: Map[K, V], k: K, from: Option[K], until: Option[K]) => - val map = mutable.TreeMap[K, V]() - map ++= entries - - val mapView = map.rangeImpl(from, until) - val newLower = Some(from.fold(k)(ord.max(_, k))) - mapView.iteratorFrom(k).toSeq == entriesInView(entries, newLower, until).toSeq.sorted - } - - property("keysIteratorFrom") = forAll { (entries: Map[K, V], k: K, from: Option[K], until: Option[K]) => - val map = mutable.TreeMap[K, V]() - map ++= entries - - val mapView = map.rangeImpl(from, until) - val newLower = Some(from.fold(k)(ord.max(_, k))) - mapView.keysIteratorFrom(k).toSeq == entriesInView(entries, newLower, until).toSeq.sorted.map(_._1) - } - - property("valuesIteratorFrom") = forAll { (entries: Map[K, V], k: K, from: Option[K], until: Option[K]) => - val map = mutable.TreeMap[K, V]() - map ++= entries - - val mapView = map.rangeImpl(from, until) - val newLower = Some(from.fold(k)(ord.max(_, k))) - mapView.valuesIteratorFrom(k).toSeq == entriesInView(entries, newLower, until).toSeq.sorted.map(_._2) - } - - property("headOption") = forAll { (map: mutable.TreeMap[K, V], from: Option[K], until: Option[K]) => - val mapView = map.rangeImpl(from, until) - mapView.headOption == Try(entriesInView(map.iterator, from, until).next()).toOption - } - - property("lastOption") = forAll { (map: mutable.TreeMap[K, V], from: Option[K], until: Option[K]) => - val mapView = map.rangeImpl(from, until) - mapView.lastOption == Try(entriesInView(map.iterator, from, until).max).toOption - } - - property("clear") = forAll { (map: mutable.TreeMap[K, V], from: Option[K], until: Option[K]) => - val mapView = map.rangeImpl(from, until) - mapView.clear() - map.isEmpty && mapView.isEmpty && map.size == 0 && mapView.size == 0 - } - - property("serializable") = forAll { (map: mutable.TreeMap[K, V], from: Option[K], until: Option[K]) => - val mapView = map.rangeImpl(from, until) - - val bytesOut = new ByteArrayOutputStream() - val out = new ObjectOutputStream(bytesOut) - out.writeObject(mapView) - val bytes = bytesOut.toByteArray - - val in = new ObjectInputStream(new ByteArrayInputStream(bytes)) - val sameMapView = in.readObject().asInstanceOf[mutable.TreeMap[K, V]] - mapView.iterator.toSeq == sameMapView.iterator.toSeq - } - } -} - -object Test extends Properties("mutable.TreeMap") { - import scala.collection.mutable._ - include(RedBlackTreeProperties) - include(MutableTreeMapProperties) - include(MutableTreeMapViewProperties) -} diff --git a/test/files/scalacheck/MutableTreeSet.scala b/test/files/scalacheck/MutableTreeSet.scala deleted file mode 100644 index bcb1d0ed94..0000000000 --- a/test/files/scalacheck/MutableTreeSet.scala +++ /dev/null @@ -1,216 +0,0 @@ -import java.io._ - -import org.scalacheck._ -import org.scalacheck.Arbitrary._ -import org.scalacheck.Prop.forAll - -import scala.collection.generic.CanBuildFrom -import scala.collection.immutable -import scala.collection.mutable -import scala.util.Try - -package scala.collection.mutable { - - object MutableTreeSetProperties extends Properties("mutable.TreeSet") { - type K = String - - property("size, isEmpty") = forAll { (elems: Set[K]) => - val set = mutable.TreeSet[K]() - set ++= elems - set.size == elems.size && set.isEmpty == elems.isEmpty - } - - property("+=") = forAll { (set: mutable.TreeSet[K], k: K) => - val oldSize = set.size - val containedKeyBefore = set.contains(k) - val newExpectedSize = if(containedKeyBefore) oldSize else oldSize + 1 - - set += k - set.contains(k) && set.size == newExpectedSize - } - - property("++=") = forAll { (set: mutable.TreeSet[K], ks: Seq[K]) => - val oldElems = set.toList - set ++= ks - (oldElems ++ ks).forall(set.contains) - } - - property("-=") = forAll { (set: mutable.TreeSet[K], k: K) => - val oldSize = set.size - val containedKeyBefore = set.contains(k) - val newExpectedSize = if(containedKeyBefore) oldSize - 1 else oldSize - - set -= k - !set.contains(k) && set.size == newExpectedSize - } - - property("--=") = forAll { (set: mutable.TreeSet[K], ks: Seq[K]) => - val oldElems = set.toList - set --= ks - val deletedElems = ks.toSet - oldElems.forall { e => set.contains(e) == !deletedElems(e) } - } - - property("iterator") = forAll { (ks: Set[K]) => - val set = mutable.TreeSet[K]() - set ++= ks - - set.iterator.toSeq == ks.toSeq.sorted - } - - property("iteratorFrom, keysIteratorFrom") = forAll { (ks: Set[K], k: K) => - val set = mutable.TreeSet[K]() - set ++= ks - - set.iteratorFrom(k).toSeq == ks.filter(_ >= k).toSeq.sorted - set.keysIteratorFrom(k).toSeq == ks.filter(_ >= k).toSeq.sorted - } - - property("headOption") = forAll { (set: mutable.TreeSet[K]) => - set.headOption == Try(set.iterator.next()).toOption - } - - property("lastOption") = forAll { (set: mutable.TreeSet[K]) => - set.lastOption == Try(set.iterator.max).toOption - } - - property("clear") = forAll { (set: mutable.TreeSet[K]) => - set.clear() - set.isEmpty && set.size == 0 - } - - property("serializable") = forAll { (set: mutable.TreeSet[K]) => - val bytesOut = new ByteArrayOutputStream() - val out = new ObjectOutputStream(bytesOut) - out.writeObject(set) - val bytes = bytesOut.toByteArray - - val in = new ObjectInputStream(new ByteArrayInputStream(bytes)) - val sameSet = in.readObject().asInstanceOf[mutable.TreeSet[K]] - set.iterator.toSeq == sameSet.iterator.toSeq - } - - property("same behavior as immutable.TreeMap") = forAll { ops: Seq[Either[K, K]] => - var iset = immutable.TreeSet[K]() - val mset = mutable.TreeSet[K]() - - ops.foreach { - case Left(k) => iset += k; mset += k - case Right(k) => iset -= k; mset -= k - } - - iset.toList == mset.toList - } - } - - object MutableTreeSetViewProperties extends Properties("mutable.TreeSetView") { - type K = String - - implicit val ord = implicitly[Ordering[K]] - - def in(key: K, from: Option[K], until: Option[K]) = - from.fold(true)(_ <= key) && until.fold(true)(_ > key) - - def keysInView[This <: TraversableOnce[K], That](keys: This, from: Option[K], until: Option[K])(implicit bf: CanBuildFrom[This, K, That]) = { - (bf.apply(keys) ++= keys.filter(in(_, from, until))).result() - } - - property("size, isEmpty") = forAll { (keys: Set[K], from: Option[K], until: Option[K]) => - val map = mutable.TreeSet[K]() - map ++= keys - - val mapView = map.rangeImpl(from, until) - mapView.size == keysInView(keys, from, until).size && - mapView.isEmpty == !keys.exists(in(_, from, until)) - } - - property("+=") = forAll { (set: mutable.TreeSet[K], k: K, from: Option[K], until: Option[K]) => - val oldSize = set.size - val containedKeyBefore = set.contains(k) - val newExpectedSize = if(containedKeyBefore) oldSize else oldSize + 1 - val isInRange = in(k, from, until) - - val setView = set.rangeImpl(from, until) - setView += k - - set.contains(k) && set.size == newExpectedSize && setView.contains(k) == isInRange - } - - property("++=") = forAll { (set: mutable.TreeSet[K], ks: Seq[K], from: Option[K], until: Option[K]) => - val setView = set.rangeImpl(from, until) - setView ++= ks - ks.toSet.forall { k => - set.contains(k) && setView.contains(k) == in(k, from, until) - } - } - - property("-=") = forAll { (set: mutable.TreeSet[K], k: K, from: Option[K], until: Option[K]) => - val oldSize = set.size - val containedKeyBefore = set.contains(k) - val newExpectedSize = if(containedKeyBefore) oldSize - 1 else oldSize - - val setView = set.rangeImpl(from, until) - setView -= k - - !set.contains(k) && set.size == newExpectedSize && !setView.contains(k) - } - - property("--=") = forAll { (set: mutable.TreeSet[K], ks: Seq[K], from: Option[K], until: Option[K]) => - val setView = set.rangeImpl(from, until) - setView --= ks - ks.toSet.forall { k => !set.contains(k) && !setView.contains(k) } - } - - property("iterator") = forAll { (ks: Set[K], from: Option[K], until: Option[K]) => - val set = mutable.TreeSet[K]() - set ++= ks - - val setView = set.rangeImpl(from, until) - setView.iterator.toSeq == keysInView(ks, from, until).toSeq.sorted - } - - property("iteratorFrom, keysIteratorFrom") = forAll { (ks: Set[K], k: K, from: Option[K], until: Option[K]) => - val set = mutable.TreeSet[K]() - set ++= ks - - val setView = set.rangeImpl(from, until) - val newLower = Some(from.fold(k)(ord.max(_, k))) - setView.iteratorFrom(k).toSeq == keysInView(ks, newLower, until).toSeq.sorted - } - - property("headOption") = forAll { (set: mutable.TreeSet[K], from: Option[K], until: Option[K]) => - val setView = set.rangeImpl(from, until) - setView.headOption == Try(keysInView(set.iterator, from, until).next()).toOption - } - - property("lastOption") = forAll { (set: mutable.TreeSet[K], from: Option[K], until: Option[K]) => - val setView = set.rangeImpl(from, until) - setView.lastOption == Try(keysInView(set.iterator, from, until).max).toOption - } - - property("clear") = forAll { (set: mutable.TreeSet[K], from: Option[K], until: Option[K]) => - val setView = set.rangeImpl(from, until) - setView.clear() - set.isEmpty && setView.isEmpty && set.size == 0 && setView.size == 0 - } - - property("serializable") = forAll { (set: mutable.TreeSet[K], from: Option[K], until: Option[K]) => - val setView = set.rangeImpl(from, until) - - val bytesOut = new ByteArrayOutputStream() - val out = new ObjectOutputStream(bytesOut) - out.writeObject(setView) - val bytes = bytesOut.toByteArray - - val in = new ObjectInputStream(new ByteArrayInputStream(bytes)) - val sameSetView = in.readObject().asInstanceOf[mutable.TreeSet[K]] - setView.iterator.toSeq == sameSetView.iterator.toSeq - } - } -} - -object Test extends Properties("mutable.TreeSet") { - import scala.collection.mutable._ - include(MutableTreeSetProperties) - include(MutableTreeSetViewProperties) -} diff --git a/test/files/scalacheck/parallel-collections/pc.scala b/test/files/scalacheck/parallel-collections/pc.scala deleted file mode 100644 index a3c1df4054..0000000000 --- a/test/files/scalacheck/parallel-collections/pc.scala +++ /dev/null @@ -1,71 +0,0 @@ -/* - * scalac: -deprecation - * scalacheck: -workers 1 -minSize 0 -maxSize 4000 -minSuccessfulTests 5 - */ - -import org.scalacheck._ -import scala.collection.parallel._ - -// package here to be able access the package-private implementation and shutdown the pool -package scala { - - class ParCollProperties extends Properties("Parallel collections") { - - def includeAllTestsWith(support: TaskSupport) { - // parallel arrays with default task support - include(new mutable.IntParallelArrayCheck(support)) - - // parallel ranges - include(new immutable.ParallelRangeCheck(support)) - - // parallel immutable hash maps (tries) - include(new immutable.IntIntParallelHashMapCheck(support)) - - // parallel immutable hash sets (tries) - include(new immutable.IntParallelHashSetCheck(support)) - - // parallel mutable hash maps (tables) - include(new mutable.IntIntParallelHashMapCheck(support)) - - // parallel ctrie - include(new mutable.IntIntParallelConcurrentTrieMapCheck(support)) - - // parallel mutable hash sets (tables) - include(new mutable.IntParallelHashSetCheck(support)) - - // parallel vectors - include(new immutable.IntParallelVectorCheck(support)) - } - - includeAllTestsWith(defaultTaskSupport) - - val ec = scala.concurrent.ExecutionContext.fromExecutorService(java.util.concurrent.Executors.newFixedThreadPool(5)) - val ectasks = new collection.parallel.ExecutionContextTaskSupport(ec) - includeAllTestsWith(ectasks) - - // no post test hooks in scalacheck, so cannot do: - // ec.shutdown() - - } - -} - - -object Test extends scala.ParCollProperties { - /* - def main(args: Array[String]) { - val pc = new ParCollProperties - org.scalacheck.Test.checkProperties( - org.scalacheck.Test.Params( - rng = new java.util.Random(5134L), - testCallback = new ConsoleReporter(0), - workers = 1, - minSize = 0, - maxSize = 4000, - minSuccessfulTests = 5 - ), - pc - ) - } - */ -} diff --git a/test/files/scalacheck/quasiquotes/Test.scala b/test/files/scalacheck/quasiquotes/Test.scala deleted file mode 100644 index 7a26fa4923..0000000000 --- a/test/files/scalacheck/quasiquotes/Test.scala +++ /dev/null @@ -1,19 +0,0 @@ -import org.scalacheck._ - -object Test extends Properties("quasiquotes") { - include(TermConstructionProps) - include(TermDeconstructionProps) - include(TypeConstructionProps) - include(TypeDeconstructionProps) - include(PatternConstructionProps) - include(PatternDeconstructionProps) - include(LiftableProps) - include(UnliftableProps) - include(ErrorProps) - include(RuntimeErrorProps) - include(DefinitionConstructionProps) - include(DefinitionDeconstructionProps) - include(DeprecationProps) - include(ForProps) - include(TypecheckedProps) -} diff --git a/test/files/scalacheck/redblacktree.scala b/test/files/scalacheck/redblacktree.scala deleted file mode 100644 index 4ded37b35a..0000000000 --- a/test/files/scalacheck/redblacktree.scala +++ /dev/null @@ -1,258 +0,0 @@ -import collection.immutable.{RedBlackTree => RB} -import org.scalacheck._ -import Prop._ -import Gen._ - -/* -Properties of a Red & Black Tree: - -A node is either red or black. -The root is black. (This rule is used in some definitions and not others. Since the -root can always be changed from red to black but not necessarily vice-versa this -rule has little effect on analysis.) -All leaves are black. -Both children of every red node are black. -Every simple path from a given node to any of its descendant leaves contains the same number of black nodes. -*/ - -package scala.collection.immutable.redblacktree { - abstract class RedBlackTreeTest extends Properties("RedBlackTree") { - def minimumSize = 0 - def maximumSize = 5 - - import RB._ - - def nodeAt[A](tree: Tree[String, A], n: Int): Option[(String, A)] = if (n < iterator(tree).size && n >= 0) - Some(iterator(tree).drop(n).next) - else - None - - def treeContains[A](tree: Tree[String, A], key: String) = iterator(tree).map(_._1) contains key - - def height(tree: Tree[_, _]): Int = if (tree eq null) 0 else (1 + math.max(height(tree.left), height(tree.right))) - - def mkTree(level: Int, parentIsBlack: Boolean = false, label: String = ""): Gen[Tree[String, Int]] = - if (level == 0) { - const(null) - } else { - for { - oddOrEven <- choose(0, 2) - tryRed = oddOrEven.sample.get % 2 == 0 // work around arbitrary[Boolean] bug - isRed = parentIsBlack && tryRed - nextLevel = if (isRed) level else level - 1 - left <- mkTree(nextLevel, !isRed, label + "L") - right <- mkTree(nextLevel, !isRed, label + "R") - } yield { - if (isRed) - RedTree(label + "N", 0, left, right) - else - BlackTree(label + "N", 0, left, right) - } - } - - def genTree = for { - depth <- choose(minimumSize, maximumSize + 1) - tree <- mkTree(depth) - } yield tree - - type ModifyParm - def genParm(tree: Tree[String, Int]): Gen[ModifyParm] - def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] - - def genInput: Gen[(Tree[String, Int], ModifyParm, Tree[String, Int])] = for { - tree <- genTree - parm <- genParm(tree) - } yield (tree, parm, modify(tree, parm)) - } - - trait RedBlackTreeInvariants { - self: RedBlackTreeTest => - - import RB._ - - def rootIsBlack[A](t: Tree[String, A]) = isBlack(t) - - def areAllLeavesBlack[A](t: Tree[String, A]): Boolean = t match { - case null => isBlack(t) - case ne => List(ne.left, ne.right) forall areAllLeavesBlack - } - - def areRedNodeChildrenBlack[A](t: Tree[String, A]): Boolean = t match { - case RedTree(_, _, left, right) => List(left, right) forall (t => isBlack(t) && areRedNodeChildrenBlack(t)) - case BlackTree(_, _, left, right) => List(left, right) forall areRedNodeChildrenBlack - case null => true - } - - def blackNodesToLeaves[A](t: Tree[String, A]): List[Int] = t match { - case null => List(1) - case BlackTree(_, _, left, right) => List(left, right) flatMap blackNodesToLeaves map (_ + 1) - case RedTree(_, _, left, right) => List(left, right) flatMap blackNodesToLeaves - } - - def areBlackNodesToLeavesEqual[A](t: Tree[String, A]): Boolean = t match { - case null => true - case ne => - ( - blackNodesToLeaves(ne).distinct.size == 1 - && areBlackNodesToLeavesEqual(ne.left) - && areBlackNodesToLeavesEqual(ne.right) - ) - } - - def orderIsPreserved[A](t: Tree[String, A]): Boolean = - iterator(t) zip iterator(t).drop(1) forall { case (x, y) => x._1 < y._1 } - - def heightIsBounded(t: Tree[_, _]): Boolean = height(t) <= (2 * (32 - Integer.numberOfLeadingZeros(count(t) + 2)) - 2) - - def setup(invariant: Tree[String, Int] => Boolean) = forAll(genInput) { case (tree, parm, newTree) => - invariant(newTree) - } - - property("root is black") = setup(rootIsBlack) - property("all leaves are black") = setup(areAllLeavesBlack) - property("children of red nodes are black") = setup(areRedNodeChildrenBlack) - property("black nodes are balanced") = setup(areBlackNodesToLeavesEqual) - property("ordering of keys is preserved") = setup(orderIsPreserved) - property("height is bounded") = setup(heightIsBounded) - } - - object TestInsert extends RedBlackTreeTest with RedBlackTreeInvariants { - import RB._ - - override type ModifyParm = Int - override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = choose(0, iterator(tree).size + 1) - override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = update(tree, generateKey(tree, parm), 0, true) - - def generateKey(tree: Tree[String, Int], parm: ModifyParm): String = nodeAt(tree, parm) match { - case Some((key, _)) => key.init.mkString + "MN" - case None => nodeAt(tree, parm - 1) match { - case Some((key, _)) => key.init.mkString + "RN" - case None => "N" - } - } - - property("update adds elements") = forAll(genInput) { case (tree, parm, newTree) => - treeContains(newTree, generateKey(tree, parm)) - } - } - - object TestModify extends RedBlackTreeTest { - import RB._ - - def newValue = 1 - override def minimumSize = 1 - override type ModifyParm = Int - override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = choose(0, iterator(tree).size) - override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = nodeAt(tree, parm) map { - case (key, _) => update(tree, key, newValue, true) - } getOrElse tree - - property("update modifies values") = forAll(genInput) { case (tree, parm, newTree) => - nodeAt(tree,parm) forall { case (key, _) => - iterator(newTree) contains (key, newValue) - } - } - } - - object TestDelete extends RedBlackTreeTest with RedBlackTreeInvariants { - import RB._ - - override def minimumSize = 1 - override type ModifyParm = Int - override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = choose(0, iterator(tree).size) - override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = nodeAt(tree, parm) map { - case (key, _) => delete(tree, key) - } getOrElse tree - - property("delete removes elements") = forAll(genInput) { case (tree, parm, newTree) => - nodeAt(tree, parm) forall { case (key, _) => - !treeContains(newTree, key) - } - } - } - - object TestRange extends RedBlackTreeTest with RedBlackTreeInvariants { - import RB._ - - override type ModifyParm = (Option[Int], Option[Int]) - override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = for { - from <- choose(0, iterator(tree).size) - to <- choose(0, iterator(tree).size) suchThat (from <=) - optionalFrom <- oneOf(Some(from), None, Some(from)) // Double Some(n) to get around a bug - optionalTo <- oneOf(Some(to), None, Some(to)) // Double Some(n) to get around a bug - } yield (optionalFrom, optionalTo) - - override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = { - val from = parm._1 flatMap (nodeAt(tree, _) map (_._1)) - val to = parm._2 flatMap (nodeAt(tree, _) map (_._1)) - rangeImpl(tree, from, to) - } - - property("range boundaries respected") = forAll(genInput) { case (tree, parm, newTree) => - val from = parm._1 flatMap (nodeAt(tree, _) map (_._1)) - val to = parm._2 flatMap (nodeAt(tree, _) map (_._1)) - ("lower boundary" |: (from forall ( key => keysIterator(newTree) forall (key <=)))) && - ("upper boundary" |: (to forall ( key => keysIterator(newTree) forall (key >)))) - } - - property("range returns all elements") = forAll(genInput) { case (tree, parm, newTree) => - val from = parm._1 flatMap (nodeAt(tree, _) map (_._1)) - val to = parm._2 flatMap (nodeAt(tree, _) map (_._1)) - val filteredTree = (keysIterator(tree) - .filter(key => from forall (key >=)) - .filter(key => to forall (key <)) - .toList) - filteredTree == keysIterator(newTree).toList - } - } - - object TestDrop extends RedBlackTreeTest with RedBlackTreeInvariants { - import RB._ - - override type ModifyParm = Int - override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = choose(0, iterator(tree).size) - override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = drop(tree, parm) - - property("drop") = forAll(genInput) { case (tree, parm, newTree) => - iterator(tree).drop(parm).toList == iterator(newTree).toList - } - } - - object TestTake extends RedBlackTreeTest with RedBlackTreeInvariants { - import RB._ - - override type ModifyParm = Int - override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = choose(0, iterator(tree).size) - override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = take(tree, parm) - - property("take") = forAll(genInput) { case (tree, parm, newTree) => - iterator(tree).take(parm).toList == iterator(newTree).toList - } - } - - object TestSlice extends RedBlackTreeTest with RedBlackTreeInvariants { - import RB._ - - override type ModifyParm = (Int, Int) - override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = for { - from <- choose(0, iterator(tree).size) - to <- choose(from, iterator(tree).size) - } yield (from, to) - override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = slice(tree, parm._1, parm._2) - - property("slice") = forAll(genInput) { case (tree, parm, newTree) => - iterator(tree).slice(parm._1, parm._2).toList == iterator(newTree).toList - } - } -} - -object Test extends Properties("RedBlackTree") { - import collection.immutable.redblacktree._ - include(TestInsert) - include(TestModify) - include(TestDelete) - include(TestRange) - include(TestDrop) - include(TestTake) - include(TestSlice) -} diff --git a/test/files/scalacheck/test.scala b/test/files/scalacheck/test.scala deleted file mode 100644 index f69c7fe211..0000000000 --- a/test/files/scalacheck/test.scala +++ /dev/null @@ -1,8 +0,0 @@ -import org.scalacheck._ - - - - - - -object Test extends Properties("Nothing") diff --git a/test/files/scalacheck/testdir/dep.scala b/test/files/scalacheck/testdir/dep.scala deleted file mode 100644 index ab167cbc8b..0000000000 --- a/test/files/scalacheck/testdir/dep.scala +++ /dev/null @@ -1,7 +0,0 @@ - - - - -object Dependency { - val v = 1 -} diff --git a/test/files/scalacheck/testdir/test.scala b/test/files/scalacheck/testdir/test.scala deleted file mode 100644 index d5a5056137..0000000000 --- a/test/files/scalacheck/testdir/test.scala +++ /dev/null @@ -1,10 +0,0 @@ -import org.scalacheck._ - - - - - - -object Test extends Properties("Nothing") { - val d = Dependency.v -} diff --git a/test/files/scalacheck/CheckCollections.scala b/test/scalacheck/CheckCollections.scala index 329d505b47..d94b71d150 100644 --- a/test/files/scalacheck/CheckCollections.scala +++ b/test/scalacheck/CheckCollections.scala @@ -3,7 +3,7 @@ import org.scalacheck.Prop._ import scala.reflect.internal.util.Collections._ -object Test extends Properties("reflect.internal.util.Collections") { +object CheckCollectionsTest extends Properties("reflect.internal.util.Collections") { def map2ConserveOld[A <: AnyRef, B](xs: List[A], ys: List[B])(f: (A, B) => A): List[A] = if (xs.isEmpty || ys.isEmpty) xs else { diff --git a/test/files/scalacheck/CheckEither.scala b/test/scalacheck/CheckEither.scala index f0ec797045..48b90c1d9b 100644 --- a/test/files/scalacheck/CheckEither.scala +++ b/test/scalacheck/CheckEither.scala @@ -5,7 +5,7 @@ import org.scalacheck.Prop._ import org.scalacheck.Test.check import Function.tupled -object Test extends Properties("Either") { +object CheckEitherTest extends Properties("Either") { implicit def arbitraryEither[X, Y](implicit xa: Arbitrary[X], ya: Arbitrary[Y]): Arbitrary[Either[X, Y]] = Arbitrary[Either[X, Y]](oneOf(arbitrary[X].map(Left(_)), arbitrary[Y].map(Right(_)))) diff --git a/test/files/scalacheck/Ctrie.scala b/test/scalacheck/Ctrie.scala index eef9d06f37..8a24079ad3 100644 --- a/test/files/scalacheck/Ctrie.scala +++ b/test/scalacheck/Ctrie.scala @@ -1,6 +1,3 @@ - - - import org.scalacheck._ import Prop._ import org.scalacheck.Gen._ @@ -16,7 +13,7 @@ case class Wrap(i: Int) { /** A check mainly oriented towards checking snapshot correctness. */ -object Test extends Properties("concurrent.TrieMap") { +object CtrieTest extends Properties("concurrent.TrieMap") { /* generators */ diff --git a/test/files/scalacheck/MutablePriorityQueue.scala b/test/scalacheck/MutablePriorityQueue.scala index 687e2e7c62..1df432d811 100644 --- a/test/files/scalacheck/MutablePriorityQueue.scala +++ b/test/scalacheck/MutablePriorityQueue.scala @@ -3,7 +3,7 @@ import org.scalacheck._ import Prop._ import Arbitrary._ -object Test extends Properties("PriorityQueue") { +object MutablePriorityQueueTest extends Properties("PriorityQueue") { type E = Int // the element type used for most/all of the tests def checkInvariant[A](pq: PriorityQueue[A])(implicit ord: Ordering[A]): Boolean = { diff --git a/test/scalacheck/MutableTreeMap.scala b/test/scalacheck/MutableTreeMap.scala new file mode 100644 index 0000000000..e3c19b8841 --- /dev/null +++ b/test/scalacheck/MutableTreeMap.scala @@ -0,0 +1,337 @@ +package scala.collection.mutable + +import java.io._ + +import org.scalacheck._ +import org.scalacheck.Arbitrary._ +import org.scalacheck.Prop.forAll + +import scala.collection.generic.CanBuildFrom +import scala.collection.immutable +import scala.collection.mutable +import scala.util.Try +import scala.collection.mutable.{RedBlackTree => RB} + +trait Generators { + + def genRedBlackTree[A: Arbitrary: Ordering, B: Arbitrary]: Gen[RB.Tree[A, B]] = { + import org.scalacheck.Gen._ + for { entries <- listOf(arbitrary[(A, B)]) } yield { + val tree = RB.Tree.empty[A, B] + entries.foreach { case (k, v) => RB.insert(tree, k, v) } + tree + } + } + + // Note: in scalacheck 1.12.2 tree maps can be automatically generated without the need for custom + // machinery + def genTreeMap[A: Arbitrary: Ordering, B: Arbitrary]: Gen[mutable.TreeMap[A, B]] = { + import org.scalacheck.Gen._ + for { + keys <- listOf(arbitrary[A]) + values <- listOfN(keys.size, arbitrary[B]) + } yield mutable.TreeMap(keys zip values: _*) + } + + implicit def arbRedBlackTree[A: Arbitrary: Ordering, B: Arbitrary] = Arbitrary(genRedBlackTree[A, B]) + implicit def arbTreeMap[A: Arbitrary: Ordering, B: Arbitrary] = Arbitrary(genTreeMap[A, B]) +} + +object RedBlackTreeProperties extends Properties("mutable.RedBlackTree") with Generators { + type K = String + type V = Int + + property("initial invariants") = forAll { (tree: RB.Tree[K, V]) => + RB.isValid(tree) + } + + property("insert") = forAll { (tree: RB.Tree[K, V], entries: Seq[(K, V)]) => + entries.foreach { case (k, v) => RB.insert(tree, k, v) } + RB.isValid(tree) && entries.toMap.forall { case (k, v) => RB.get(tree, k) == Some(v) } + } + + property("delete") = forAll { (tree: RB.Tree[K, V], ks: Seq[K]) => + ks.foreach { k => RB.delete(tree, k) } + RB.isValid(tree) && ks.toSet.forall { k => RB.get(tree, k) == None } + } + + property("insert & delete") = forAll { (tree: RB.Tree[K, V], ops: Seq[Either[(K, V), K]]) => + ops.foreach { + case Left((k, v)) => RB.insert(tree, k, v) + case Right(k) => RB.delete(tree, k) + } + RB.isValid(tree) + } + + property("min") = forAll { (entries: Seq[(K, V)]) => + val tree = RB.Tree.empty[K, V] + entries.foreach { case (k, v) => RB.insert(tree, k, v) } + RB.min(tree) == (if (entries.isEmpty) None else Some(entries.toMap.min)) + } + + property("max") = forAll { (entries: Seq[(K, V)]) => + val tree = RB.Tree.empty[K, V] + entries.foreach { case (k, v) => RB.insert(tree, k, v) } + RB.max(tree) == (if (entries.isEmpty) None else Some(entries.toMap.max)) + } +} + +object MutableTreeMapProperties extends Properties("mutable.TreeMap") with Generators { + type K = String + type V = Int + + property("get, contains") = forAll { (allEntries: Map[K, V]) => + val entries = allEntries.take(allEntries.size / 2) + + val map = mutable.TreeMap[K, V]() + map ++= entries + + allEntries.forall { case (k, v) => + map.contains(k) == entries.contains(k) && + map.get(k) == entries.get(k) + } + } + + property("size, isEmpty") = forAll { (entries: Map[K, V]) => + val map = mutable.TreeMap[K, V]() + map ++= entries + map.size == entries.size && map.isEmpty == entries.isEmpty + } + + property("+=") = forAll { (map: mutable.TreeMap[K, V], k: K, v: V) => + val oldSize = map.size + val containedKeyBefore = map.contains(k) + val newExpectedSize = if(containedKeyBefore) oldSize else oldSize + 1 + + map += (k -> v) + map.contains(k) && map.get(k) == Some(v) && map.size == newExpectedSize + } + + property("++=") = forAll { (map: mutable.TreeMap[K, V], entries: Seq[(K, V)]) => + val oldEntries = map.toMap + map ++= entries + (oldEntries ++ entries).forall { case (k, v) => map.get(k) == Some(v) } + } + + property("-=") = forAll { (map: mutable.TreeMap[K, V], k: K) => + val oldSize = map.size + val containedKeyBefore = map.contains(k) + val newExpectedSize = if(containedKeyBefore) oldSize - 1 else oldSize + + map -= k + !map.contains(k) && map.get(k) == None && map.size == newExpectedSize + } + + property("--=") = forAll { (map: mutable.TreeMap[K, V], ks: Seq[K]) => + val oldElems = map.toList + map --= ks + val deletedElems = ks.toSet + oldElems.forall { case (k, v) => map.get(k) == (if(deletedElems(k)) None else Some(v)) } + } + + property("iterator") = forAll { (entries: Map[K, V]) => + val map = mutable.TreeMap[K, V]() + map ++= entries + + map.iterator.toSeq == entries.toSeq.sorted + } + + property("iteratorFrom") = forAll { (entries: Map[K, V], k: K) => + val map = mutable.TreeMap[K, V]() + map ++= entries + + map.iteratorFrom(k).toSeq == entries.filterKeys(_ >= k).toSeq.sorted + } + + property("keysIteratorFrom") = forAll { (entries: Map[K, V], k: K) => + val map = mutable.TreeMap[K, V]() + map ++= entries + + map.keysIteratorFrom(k).toSeq == entries.keysIterator.filter(_ >= k).toSeq.sorted + } + + property("valuesIteratorFrom") = forAll { (entries: Map[K, V], k: K) => + val map = mutable.TreeMap[K, V]() + map ++= entries + + map.valuesIteratorFrom(k).toSeq == entries.filterKeys(_ >= k).toSeq.sorted.map(_._2) + } + + property("headOption") = forAll { (map: mutable.TreeMap[K, V]) => + map.headOption == Try(map.iterator.next()).toOption + } + + property("lastOption") = forAll { (map: mutable.TreeMap[K, V]) => + map.lastOption == Try(map.iterator.max).toOption + } + + property("clear") = forAll { (map: mutable.TreeMap[K, V]) => + map.clear() + map.isEmpty && map.size == 0 + } + + property("serializable") = forAll { (map: mutable.TreeMap[K, V]) => + val bytesOut = new ByteArrayOutputStream() + val out = new ObjectOutputStream(bytesOut) + out.writeObject(map) + val bytes = bytesOut.toByteArray + + val in = new ObjectInputStream(new ByteArrayInputStream(bytes)) + val sameMap = in.readObject().asInstanceOf[mutable.TreeMap[K, V]] + map.iterator.toSeq == sameMap.iterator.toSeq + } + + property("same behavior as immutable.TreeMap") = forAll { ops: Seq[Either[(K, V), K]] => + var imap = immutable.TreeMap[K, V]() + val mmap = mutable.TreeMap[K, V]() + + ops.foreach { + case Left((k, v)) => imap += k -> v; mmap += k -> v + case Right(k) => imap -= k; mmap -= k + } + + imap.toList == mmap.toList + } +} + +object MutableTreeMapViewProperties extends Properties("mutable.TreeMapView") with Generators { + type K = String + type V = Int + + implicit val ord = implicitly[Ordering[K]] + + def in(key: K, from: Option[K], until: Option[K]) = + from.fold(true)(_ <= key) && until.fold(true)(_ > key) + + def entriesInView[This <: TraversableOnce[(K, V)], That](entries: This, from: Option[K], until: Option[K])(implicit bf: CanBuildFrom[This, (K, V), That]) = { + (bf.apply(entries) ++= entries.filter { case (k, _) => in(k, from, until) }).result() + } + + property("get, contains") = forAll { (allEntries: Map[K, V], from: Option[K], until: Option[K]) => + val entries = allEntries.take(allEntries.size / 2) + + val map = mutable.TreeMap[K, V]() + map ++= entries + + val mapView = map.rangeImpl(from, until) + allEntries.forall { case (k, v) => + mapView.contains(k) == (in(k, from, until) && entries.contains(k)) && + mapView.get(k) == (if(in(k, from, until)) entries.get(k) else None) + } + } + + property("size, isEmpty") = forAll { (entries: Map[K, V], from: Option[K], until: Option[K]) => + val map = mutable.TreeMap[K, V]() + map ++= entries + + val mapView = map.rangeImpl(from, until) + mapView.size == entriesInView(entries, from, until).size && + mapView.isEmpty == !entries.exists { kv => in(kv._1, from, until) } + } + + property("+=") = forAll { (map: mutable.TreeMap[K, V], k: K, v: V, from: Option[K], until: Option[K]) => + val oldSize = map.size + val containedKeyBefore = map.contains(k) + val newExpectedSize = if(containedKeyBefore) oldSize else oldSize + 1 + val isInRange = in(k, from, until) + + val mapView = map.rangeImpl(from, until) + mapView += (k -> v) + + map.contains(k) && map.get(k) == Some(v) && map.size == newExpectedSize && + mapView.contains(k) == isInRange && + mapView.get(k) == (if(isInRange) Some(v) else None) + } + + property("++=") = forAll { (map: mutable.TreeMap[K, V], entries: Seq[(K, V)], from: Option[K], until: Option[K]) => + val mapView = map.rangeImpl(from, until) + mapView ++= entries + entries.toMap.forall { case (k, v) => + map.get(k) == Some(v) && + mapView.get(k) == (if (in(k, from, until)) Some(v) else None) + } + } + + property("-=") = forAll { (map: mutable.TreeMap[K, V], k: K, from: Option[K], until: Option[K]) => + val oldSize = map.size + val containedKeyBefore = map.contains(k) + val newExpectedSize = if(containedKeyBefore) oldSize - 1 else oldSize + + val mapView = map.rangeImpl(from, until) + mapView -= k + + !map.contains(k) && map.get(k) == None && map.size == newExpectedSize && + !mapView.contains(k) && + mapView.get(k) == None + } + + property("--=") = forAll { (map: mutable.TreeMap[K, V], ks: Seq[K], from: Option[K], until: Option[K]) => + val mapView = map.rangeImpl(from, until) + mapView --= ks + ks.toSet.forall { k => map.get(k) == None && mapView.get(k) == None } + } + + property("iterator") = forAll { (entries: Map[K, V], from: Option[K], until: Option[K]) => + val map = mutable.TreeMap[K, V]() + map ++= entries + + val mapView = map.rangeImpl(from, until) + mapView.iterator.toSeq == entriesInView(entries, from, until).toSeq.sorted + } + + property("iteratorFrom") = forAll { (entries: Map[K, V], k: K, from: Option[K], until: Option[K]) => + val map = mutable.TreeMap[K, V]() + map ++= entries + + val mapView = map.rangeImpl(from, until) + val newLower = Some(from.fold(k)(ord.max(_, k))) + mapView.iteratorFrom(k).toSeq == entriesInView(entries, newLower, until).toSeq.sorted + } + + property("keysIteratorFrom") = forAll { (entries: Map[K, V], k: K, from: Option[K], until: Option[K]) => + val map = mutable.TreeMap[K, V]() + map ++= entries + + val mapView = map.rangeImpl(from, until) + val newLower = Some(from.fold(k)(ord.max(_, k))) + mapView.keysIteratorFrom(k).toSeq == entriesInView(entries, newLower, until).toSeq.sorted.map(_._1) + } + + property("valuesIteratorFrom") = forAll { (entries: Map[K, V], k: K, from: Option[K], until: Option[K]) => + val map = mutable.TreeMap[K, V]() + map ++= entries + + val mapView = map.rangeImpl(from, until) + val newLower = Some(from.fold(k)(ord.max(_, k))) + mapView.valuesIteratorFrom(k).toSeq == entriesInView(entries, newLower, until).toSeq.sorted.map(_._2) + } + + property("headOption") = forAll { (map: mutable.TreeMap[K, V], from: Option[K], until: Option[K]) => + val mapView = map.rangeImpl(from, until) + mapView.headOption == Try(entriesInView(map.iterator, from, until).next()).toOption + } + + property("lastOption") = forAll { (map: mutable.TreeMap[K, V], from: Option[K], until: Option[K]) => + val mapView = map.rangeImpl(from, until) + mapView.lastOption == Try(entriesInView(map.iterator, from, until).max).toOption + } + + property("clear") = forAll { (map: mutable.TreeMap[K, V], from: Option[K], until: Option[K]) => + val mapView = map.rangeImpl(from, until) + mapView.clear() + map.isEmpty && mapView.isEmpty && map.size == 0 && mapView.size == 0 + } + + property("serializable") = forAll { (map: mutable.TreeMap[K, V], from: Option[K], until: Option[K]) => + val mapView = map.rangeImpl(from, until) + + val bytesOut = new ByteArrayOutputStream() + val out = new ObjectOutputStream(bytesOut) + out.writeObject(mapView) + val bytes = bytesOut.toByteArray + + val in = new ObjectInputStream(new ByteArrayInputStream(bytes)) + val sameMapView = in.readObject().asInstanceOf[mutable.TreeMap[K, V]] + mapView.iterator.toSeq == sameMapView.iterator.toSeq + } +} diff --git a/test/scalacheck/MutableTreeSet.scala b/test/scalacheck/MutableTreeSet.scala new file mode 100644 index 0000000000..d2f5a238c0 --- /dev/null +++ b/test/scalacheck/MutableTreeSet.scala @@ -0,0 +1,209 @@ +package scala.collection.mutable + +import java.io._ + +import org.scalacheck._ +import org.scalacheck.Arbitrary._ +import org.scalacheck.Prop.forAll + +import scala.collection.generic.CanBuildFrom +import scala.collection.immutable +import scala.collection.mutable +import scala.util.Try + +object MutableTreeSetProperties extends Properties("mutable.TreeSet") { + type K = String + + property("size, isEmpty") = forAll { (elems: Set[K]) => + val set = mutable.TreeSet[K]() + set ++= elems + set.size == elems.size && set.isEmpty == elems.isEmpty + } + + property("+=") = forAll { (set: mutable.TreeSet[K], k: K) => + val oldSize = set.size + val containedKeyBefore = set.contains(k) + val newExpectedSize = if(containedKeyBefore) oldSize else oldSize + 1 + + set += k + set.contains(k) && set.size == newExpectedSize + } + + property("++=") = forAll { (set: mutable.TreeSet[K], ks: Seq[K]) => + val oldElems = set.toList + set ++= ks + (oldElems ++ ks).forall(set.contains) + } + + property("-=") = forAll { (set: mutable.TreeSet[K], k: K) => + val oldSize = set.size + val containedKeyBefore = set.contains(k) + val newExpectedSize = if(containedKeyBefore) oldSize - 1 else oldSize + + set -= k + !set.contains(k) && set.size == newExpectedSize + } + + property("--=") = forAll { (set: mutable.TreeSet[K], ks: Seq[K]) => + val oldElems = set.toList + set --= ks + val deletedElems = ks.toSet + oldElems.forall { e => set.contains(e) == !deletedElems(e) } + } + + property("iterator") = forAll { (ks: Set[K]) => + val set = mutable.TreeSet[K]() + set ++= ks + + set.iterator.toSeq == ks.toSeq.sorted + } + + property("iteratorFrom, keysIteratorFrom") = forAll { (ks: Set[K], k: K) => + val set = mutable.TreeSet[K]() + set ++= ks + + set.iteratorFrom(k).toSeq == ks.filter(_ >= k).toSeq.sorted + set.keysIteratorFrom(k).toSeq == ks.filter(_ >= k).toSeq.sorted + } + + property("headOption") = forAll { (set: mutable.TreeSet[K]) => + set.headOption == Try(set.iterator.next()).toOption + } + + property("lastOption") = forAll { (set: mutable.TreeSet[K]) => + set.lastOption == Try(set.iterator.max).toOption + } + + property("clear") = forAll { (set: mutable.TreeSet[K]) => + set.clear() + set.isEmpty && set.size == 0 + } + + property("serializable") = forAll { (set: mutable.TreeSet[K]) => + val bytesOut = new ByteArrayOutputStream() + val out = new ObjectOutputStream(bytesOut) + out.writeObject(set) + val bytes = bytesOut.toByteArray + + val in = new ObjectInputStream(new ByteArrayInputStream(bytes)) + val sameSet = in.readObject().asInstanceOf[mutable.TreeSet[K]] + set.iterator.toSeq == sameSet.iterator.toSeq + } + + property("same behavior as immutable.TreeMap") = forAll { ops: Seq[Either[K, K]] => + var iset = immutable.TreeSet[K]() + val mset = mutable.TreeSet[K]() + + ops.foreach { + case Left(k) => iset += k; mset += k + case Right(k) => iset -= k; mset -= k + } + + iset.toList == mset.toList + } +} + +object MutableTreeSetViewProperties extends Properties("mutable.TreeSetView") { + type K = String + + implicit val ord = implicitly[Ordering[K]] + + def in(key: K, from: Option[K], until: Option[K]) = + from.fold(true)(_ <= key) && until.fold(true)(_ > key) + + def keysInView[This <: TraversableOnce[K], That](keys: This, from: Option[K], until: Option[K])(implicit bf: CanBuildFrom[This, K, That]) = { + (bf.apply(keys) ++= keys.filter(in(_, from, until))).result() + } + + property("size, isEmpty") = forAll { (keys: Set[K], from: Option[K], until: Option[K]) => + val map = mutable.TreeSet[K]() + map ++= keys + + val mapView = map.rangeImpl(from, until) + mapView.size == keysInView(keys, from, until).size && + mapView.isEmpty == !keys.exists(in(_, from, until)) + } + + property("+=") = forAll { (set: mutable.TreeSet[K], k: K, from: Option[K], until: Option[K]) => + val oldSize = set.size + val containedKeyBefore = set.contains(k) + val newExpectedSize = if(containedKeyBefore) oldSize else oldSize + 1 + val isInRange = in(k, from, until) + + val setView = set.rangeImpl(from, until) + setView += k + + set.contains(k) && set.size == newExpectedSize && setView.contains(k) == isInRange + } + + property("++=") = forAll { (set: mutable.TreeSet[K], ks: Seq[K], from: Option[K], until: Option[K]) => + val setView = set.rangeImpl(from, until) + setView ++= ks + ks.toSet.forall { k => + set.contains(k) && setView.contains(k) == in(k, from, until) + } + } + + property("-=") = forAll { (set: mutable.TreeSet[K], k: K, from: Option[K], until: Option[K]) => + val oldSize = set.size + val containedKeyBefore = set.contains(k) + val newExpectedSize = if(containedKeyBefore) oldSize - 1 else oldSize + + val setView = set.rangeImpl(from, until) + setView -= k + + !set.contains(k) && set.size == newExpectedSize && !setView.contains(k) + } + + property("--=") = forAll { (set: mutable.TreeSet[K], ks: Seq[K], from: Option[K], until: Option[K]) => + val setView = set.rangeImpl(from, until) + setView --= ks + ks.toSet.forall { k => !set.contains(k) && !setView.contains(k) } + } + + property("iterator") = forAll { (ks: Set[K], from: Option[K], until: Option[K]) => + val set = mutable.TreeSet[K]() + set ++= ks + + val setView = set.rangeImpl(from, until) + setView.iterator.toSeq == keysInView(ks, from, until).toSeq.sorted + } + + property("iteratorFrom, keysIteratorFrom") = forAll { (ks: Set[K], k: K, from: Option[K], until: Option[K]) => + val set = mutable.TreeSet[K]() + set ++= ks + + val setView = set.rangeImpl(from, until) + val newLower = Some(from.fold(k)(ord.max(_, k))) + setView.iteratorFrom(k).toSeq == keysInView(ks, newLower, until).toSeq.sorted + } + + property("headOption") = forAll { (set: mutable.TreeSet[K], from: Option[K], until: Option[K]) => + val setView = set.rangeImpl(from, until) + setView.headOption == Try(keysInView(set.iterator, from, until).next()).toOption + } + + property("lastOption") = forAll { (set: mutable.TreeSet[K], from: Option[K], until: Option[K]) => + val setView = set.rangeImpl(from, until) + setView.lastOption == Try(keysInView(set.iterator, from, until).max).toOption + } + + property("clear") = forAll { (set: mutable.TreeSet[K], from: Option[K], until: Option[K]) => + val setView = set.rangeImpl(from, until) + setView.clear() + set.isEmpty && setView.isEmpty && set.size == 0 && setView.size == 0 + } + + property("serializable") = forAll { (set: mutable.TreeSet[K], from: Option[K], until: Option[K]) => + val setView = set.rangeImpl(from, until) + + val bytesOut = new ByteArrayOutputStream() + val out = new ObjectOutputStream(bytesOut) + out.writeObject(setView) + val bytes = bytesOut.toByteArray + + val in = new ObjectInputStream(new ByteArrayInputStream(bytes)) + val sameSetView = in.readObject().asInstanceOf[mutable.TreeSet[K]] + setView.iterator.toSeq == sameSetView.iterator.toSeq + } +} diff --git a/test/files/scalacheck/ReflectionExtractors.scala b/test/scalacheck/ReflectionExtractors.scala index a2615feb3e..23076662fd 100644 --- a/test/files/scalacheck/ReflectionExtractors.scala +++ b/test/scalacheck/ReflectionExtractors.scala @@ -6,7 +6,7 @@ import Arbitrary._ import scala.reflect.runtime.universe._ import Flag._ -object Test extends Properties("reflection extractors") { +object ReflectionExtractorsTest extends Properties("reflection extractors") { val genFlag = oneOf( TRAIT, INTERFACE, MUTABLE, MACRO, DEFERRED, ABSTRACT, FINAL, SEALED, @@ -49,4 +49,4 @@ object Test extends Properties("reflection extractors") { priv == mods.privateWithin && annots == mods.annotations } -}
\ No newline at end of file +} diff --git a/test/files/scalacheck/Unrolled.scala b/test/scalacheck/Unrolled.scala index 34604b8667..ad6e9d3cc8 100644 --- a/test/files/scalacheck/Unrolled.scala +++ b/test/scalacheck/Unrolled.scala @@ -4,7 +4,7 @@ import Gen._ import collection.mutable.UnrolledBuffer -object Test extends Properties("UnrolledBuffer") { +object UnrolledTest extends Properties("UnrolledBuffer") { property("concat size") = forAll { (l1: List[Int], l2: List[Int]) => val u1 = new UnrolledBuffer[Int] diff --git a/test/files/scalacheck/array-new.scala b/test/scalacheck/array-new.scala index d8c69ead78..de2df68b3a 100644 --- a/test/files/scalacheck/array-new.scala +++ b/test/scalacheck/array-new.scala @@ -7,7 +7,7 @@ import util._ import Buildable._ import scala.collection.mutable.ArraySeq -object Test extends Properties("Array") { +object ArrayNewTest extends Properties("Array") { /** At this moment the authentic scalacheck Array Builder/Arb bits are commented out. */ implicit def arbArray[T](implicit a: Arbitrary[T], m: ClassTag[T]): Arbitrary[Array[T]] = @@ -34,4 +34,4 @@ object Test extends Properties("Array") { val flattened = arr flatMap (x => x) flatMap (x => x) flattened.length == i1 * i2 * i3 } -}
\ No newline at end of file +} diff --git a/test/files/scalacheck/array-old.scala b/test/scalacheck/array-old.scala index 03c0217180..9532636660 100644 --- a/test/files/scalacheck/array-old.scala +++ b/test/scalacheck/array-old.scala @@ -6,7 +6,7 @@ import util._ import Buildable._ import scala.collection.mutable.ArraySeq -object Test extends Properties("Array") { +object ArrayOldTest extends Properties("Array") { /** At this moment the authentic scalacheck Array Builder/Arb bits are commented out. */ implicit def arbArray[T](implicit a: Arbitrary[T], m: Manifest[T]): Arbitrary[Array[T]] = diff --git a/test/files/scalacheck/concurrent-map.scala b/test/scalacheck/concurrent-map.scala index 7c9b8d4169..0dae7a98bd 100755 --- a/test/files/scalacheck/concurrent-map.scala +++ b/test/scalacheck/concurrent-map.scala @@ -1,6 +1,3 @@ - - - import java.util.concurrent._ import scala.collection._ import scala.collection.JavaConverters._ @@ -8,14 +5,11 @@ import org.scalacheck._ import org.scalacheck.Prop._ import org.scalacheck.Gen._ +object ConcurrentMapTest extends Properties("concurrent.TrieMap") { - -case class Wrap(i: Int) { - override def hashCode = i * 0x9e3775cd -} - - -object Test extends Properties("concurrent.TrieMap") { + case class Wrap(i: Int) { + override def hashCode = i * 0x9e3775cd + } /* generators */ diff --git a/test/files/scalacheck/duration.scala b/test/scalacheck/duration.scala index 5e93638614..89cb9ff955 100644 --- a/test/files/scalacheck/duration.scala +++ b/test/scalacheck/duration.scala @@ -5,7 +5,7 @@ import Arbitrary._ import math._ import concurrent.duration.Duration.fromNanos -object Test extends Properties("Division of Duration by Long") { +object DurationTest extends Properties("Division of Duration by Long") { val weightedLong = frequency( diff --git a/test/files/scalacheck/list.scala b/test/scalacheck/list.scala index 5f6de95237..3531f620f9 100644 --- a/test/files/scalacheck/list.scala +++ b/test/scalacheck/list.scala @@ -2,7 +2,7 @@ import org.scalacheck._ import Prop._ import Gen._ -object Test extends Properties("List") { +object ListTest extends Properties("List") { def sorted(xs: List[Int]) = xs sortWith (_ < _) property("concat size") = forAll { (l1: List[Int], l2: List[Int]) => (l1.size + l2.size) == (l1 ::: l2).size } diff --git a/test/files/scalacheck/nan-ordering.scala b/test/scalacheck/nan-ordering.scala index 05e97a13c9..be57b27178 100644 --- a/test/files/scalacheck/nan-ordering.scala +++ b/test/scalacheck/nan-ordering.scala @@ -2,7 +2,7 @@ import org.scalacheck._ import Gen._ import Prop._ -object Test extends Properties("NaN-Ordering") { +object NanOrderingTest extends Properties("NaN-Ordering") { val specFloats: Gen[Float] = oneOf( Float.MaxValue, diff --git a/test/files/scalacheck/parallel-collections/IntOperators.scala b/test/scalacheck/parallel-collections/IntOperators.scala index 4a74b91da8..c7f43b6526 100644 --- a/test/files/scalacheck/parallel-collections/IntOperators.scala +++ b/test/scalacheck/parallel-collections/IntOperators.scala @@ -108,22 +108,3 @@ trait IntSeqOperators extends IntOperators with SeqOperators[Int] { List(-4, -3, -2, -1) ) } - - - - - - - - - - - - - - - - - - - diff --git a/test/files/scalacheck/parallel-collections/IntValues.scala b/test/scalacheck/parallel-collections/IntValues.scala index cab60ead76..cab60ead76 100644 --- a/test/files/scalacheck/parallel-collections/IntValues.scala +++ b/test/scalacheck/parallel-collections/IntValues.scala diff --git a/test/files/scalacheck/parallel-collections/Operators.scala b/test/scalacheck/parallel-collections/Operators.scala index 72133a5009..72133a5009 100644 --- a/test/files/scalacheck/parallel-collections/Operators.scala +++ b/test/scalacheck/parallel-collections/Operators.scala diff --git a/test/files/scalacheck/parallel-collections/PairOperators.scala b/test/scalacheck/parallel-collections/PairOperators.scala index fe851114be..fe851114be 100644 --- a/test/files/scalacheck/parallel-collections/PairOperators.scala +++ b/test/scalacheck/parallel-collections/PairOperators.scala diff --git a/test/files/scalacheck/parallel-collections/PairValues.scala b/test/scalacheck/parallel-collections/PairValues.scala index 864dad2425..864dad2425 100644 --- a/test/files/scalacheck/parallel-collections/PairValues.scala +++ b/test/scalacheck/parallel-collections/PairValues.scala diff --git a/test/files/scalacheck/parallel-collections/ParallelArrayCheck.scala b/test/scalacheck/parallel-collections/ParallelArrayCheck.scala index 605c16857a..39370f8c38 100644 --- a/test/files/scalacheck/parallel-collections/ParallelArrayCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelArrayCheck.scala @@ -53,20 +53,10 @@ abstract class ParallelArrayCheck[T](tp: String) extends ParallelSeqCheck[T]("Pa } -class IntParallelArrayCheck(val tasksupport: TaskSupport) extends ParallelArrayCheck[Int]("Int") with IntSeqOperators with IntValues { +abstract class IntParallelArrayCheck(val tasksupport: TaskSupport, descriptor: String) extends ParallelArrayCheck[Int](s"Int ($descriptor)") with IntSeqOperators with IntValues { override def instances(vals: Seq[Gen[Int]]) = oneOf(super.instances(vals), sized { sz => (0 until sz).toArray.toSeq }, sized { sz => (-sz until 0).toArray.toSeq }) } - - - - - - - - - - diff --git a/test/files/scalacheck/parallel-collections/ParallelArrayTest.scala b/test/scalacheck/parallel-collections/ParallelArrayTest.scala index db2b1ea01e..db2b1ea01e 100644 --- a/test/files/scalacheck/parallel-collections/ParallelArrayTest.scala +++ b/test/scalacheck/parallel-collections/ParallelArrayTest.scala diff --git a/test/files/scalacheck/parallel-collections/ParallelArrayViewCheck.scala b/test/scalacheck/parallel-collections/ParallelArrayViewCheck.scala index fb09a5bbb7..fb09a5bbb7 100644 --- a/test/files/scalacheck/parallel-collections/ParallelArrayViewCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelArrayViewCheck.scala diff --git a/test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala b/test/scalacheck/parallel-collections/ParallelCtrieCheck.scala index cf15afb3b9..ebdcf78bea 100644 --- a/test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelCtrieCheck.scala @@ -48,7 +48,7 @@ abstract class ParallelConcurrentTrieMapCheck[K, V](tp: String) extends Parallel } -class IntIntParallelConcurrentTrieMapCheck(val tasksupport: TaskSupport) extends ParallelConcurrentTrieMapCheck[Int, Int]("Int, Int") +abstract class IntIntParallelConcurrentTrieMapCheck(val tasksupport: TaskSupport, descriptor: String) extends ParallelConcurrentTrieMapCheck[Int, Int](s"Int, Int ($descriptor)") with PairOperators[Int, Int] with PairValues[Int, Int] { diff --git a/test/files/scalacheck/parallel-collections/ParallelHashMapCheck.scala b/test/scalacheck/parallel-collections/ParallelHashMapCheck.scala index 34b3f33de2..06fdb66080 100644 --- a/test/files/scalacheck/parallel-collections/ParallelHashMapCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelHashMapCheck.scala @@ -47,7 +47,7 @@ abstract class ParallelHashMapCheck[K, V](tp: String) extends ParallelMapCheck[K } -class IntIntParallelHashMapCheck(val tasksupport: TaskSupport) extends ParallelHashMapCheck[Int, Int]("Int, Int") +abstract class IntIntParallelHashMapCheck(val tasksupport: TaskSupport, descriptor: String) extends ParallelHashMapCheck[Int, Int](s"Int, Int ($descriptor)") with PairOperators[Int, Int] with PairValues[Int, Int] { diff --git a/test/files/scalacheck/parallel-collections/ParallelHashSetCheck.scala b/test/scalacheck/parallel-collections/ParallelHashSetCheck.scala index 91de2472a7..a968ed053f 100644 --- a/test/files/scalacheck/parallel-collections/ParallelHashSetCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelHashSetCheck.scala @@ -47,7 +47,7 @@ abstract class ParallelHashSetCheck[T](tp: String) extends ParallelSetCheck[T](" } -class IntParallelHashSetCheck(val tasksupport: TaskSupport) extends ParallelHashSetCheck[Int]("Int") +abstract class IntParallelHashSetCheck(val tasksupport: TaskSupport, descriptor: String) extends ParallelHashSetCheck[Int](s"Int ($descriptor)") with IntOperators with IntValues { diff --git a/test/files/scalacheck/parallel-collections/ParallelHashTrieCheck.scala b/test/scalacheck/parallel-collections/ParallelHashTrieCheck.scala index 9e29be5429..e1df95e051 100644 --- a/test/files/scalacheck/parallel-collections/ParallelHashTrieCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelHashTrieCheck.scala @@ -47,7 +47,7 @@ abstract class ParallelHashMapCheck[K, V](tp: String) extends ParallelMapCheck[K } -class IntIntParallelHashMapCheck(val tasksupport: TaskSupport) extends ParallelHashMapCheck[Int, Int]("Int, Int") +abstract class IntIntParallelHashMapCheck(val tasksupport: TaskSupport, descriptor: String) extends ParallelHashMapCheck[Int, Int](s"Int, Int ($descriptor)") with PairOperators[Int, Int] with PairValues[Int, Int] { @@ -109,7 +109,7 @@ abstract class ParallelHashSetCheck[T](tp: String) extends ParallelSetCheck[T](" } -class IntParallelHashSetCheck(val tasksupport: TaskSupport) extends ParallelHashSetCheck[Int]("Int") +abstract class IntParallelHashSetCheck(val tasksupport: TaskSupport, descriptor: String) extends ParallelHashSetCheck[Int](s"Int ($descriptor)") with IntOperators with IntValues { diff --git a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala b/test/scalacheck/parallel-collections/ParallelIterableCheck.scala index 7e7ef2ce1b..7e7ef2ce1b 100644 --- a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelIterableCheck.scala diff --git a/test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala b/test/scalacheck/parallel-collections/ParallelMapCheck1.scala index 50aa4ad0c7..50aa4ad0c7 100644 --- a/test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala +++ b/test/scalacheck/parallel-collections/ParallelMapCheck1.scala diff --git a/test/files/scalacheck/parallel-collections/ParallelRangeCheck.scala b/test/scalacheck/parallel-collections/ParallelRangeCheck.scala index a80d1a27a1..5b783fadf2 100644 --- a/test/files/scalacheck/parallel-collections/ParallelRangeCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelRangeCheck.scala @@ -17,7 +17,7 @@ import scala.collection.parallel.ops._ -class ParallelRangeCheck(val tasksupport: TaskSupport) extends ParallelSeqCheck[Int]("ParallelRange[Int]") with ops.IntSeqOperators { +abstract class ParallelRangeCheck(val tasksupport: TaskSupport, descriptor: String) extends ParallelSeqCheck[Int](s"ParallelRange[Int] ($descriptor)") with ops.IntSeqOperators { // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) diff --git a/test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala b/test/scalacheck/parallel-collections/ParallelSeqCheck.scala index 48c3d3f745..48c3d3f745 100644 --- a/test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelSeqCheck.scala diff --git a/test/files/scalacheck/parallel-collections/ParallelSetCheck.scala b/test/scalacheck/parallel-collections/ParallelSetCheck.scala index c22dddf96d..c22dddf96d 100644 --- a/test/files/scalacheck/parallel-collections/ParallelSetCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelSetCheck.scala diff --git a/test/files/scalacheck/parallel-collections/ParallelVectorCheck.scala b/test/scalacheck/parallel-collections/ParallelVectorCheck.scala index bbebd51919..1afcf2ce4c 100644 --- a/test/files/scalacheck/parallel-collections/ParallelVectorCheck.scala +++ b/test/scalacheck/parallel-collections/ParallelVectorCheck.scala @@ -53,7 +53,7 @@ abstract class ParallelVectorCheck[T](tp: String) extends collection.parallel.Pa -class IntParallelVectorCheck(val tasksupport: TaskSupport) extends ParallelVectorCheck[Int]("Int") with IntSeqOperators with IntValues { +abstract class IntParallelVectorCheck(val tasksupport: TaskSupport, descriptor: String) extends ParallelVectorCheck[Int](s"Int ($descriptor)") with IntSeqOperators with IntValues { override def instances(vals: Seq[Gen[Int]]) = oneOf(super.instances(vals), sized { sz => (0 until sz).toArray.toSeq }, sized { sz => diff --git a/test/scalacheck/parallel-collections/pc.scala b/test/scalacheck/parallel-collections/pc.scala new file mode 100644 index 0000000000..10d0643be8 --- /dev/null +++ b/test/scalacheck/parallel-collections/pc.scala @@ -0,0 +1,61 @@ +// package here to be able access the package-private implementation and shutdown the pool +package scala + +import org.scalacheck._ +import scala.collection.parallel._ + +class ParCollProperties extends Properties("Parallel collections") { + + def includeAllTestsWith(support: TaskSupport, descriptor: String) { + // parallel arrays with default task support + include(new mutable.IntParallelArrayCheck(support, descriptor) { }) + + // parallel ranges + include(new immutable.ParallelRangeCheck(support, descriptor) { }) + + // parallel immutable hash maps (tries) + include(new immutable.IntIntParallelHashMapCheck(support, descriptor) { }) + + // parallel immutable hash sets (tries) + include(new immutable.IntParallelHashSetCheck(support, descriptor) { }) + + // parallel mutable hash maps (tables) + include(new mutable.IntIntParallelHashMapCheck(support, descriptor) { }) + + // parallel ctrie + include(new mutable.IntIntParallelConcurrentTrieMapCheck(support, descriptor) { }) + + // parallel mutable hash sets (tables) + include(new mutable.IntParallelHashSetCheck(support, descriptor) { }) + + // parallel vectors + include(new immutable.IntParallelVectorCheck(support, descriptor) { }) + } + + includeAllTestsWith(defaultTaskSupport, "defaultTaskSupport") + + val ec = scala.concurrent.ExecutionContext.fromExecutorService(java.util.concurrent.Executors.newFixedThreadPool(5)) + val ectasks = new collection.parallel.ExecutionContextTaskSupport(ec) + includeAllTestsWith(ectasks, "ectasks") + + // no post test hooks in scalacheck, so cannot do: + // ec.shutdown() + +} + +/* +def main(args: Array[String]) { + val pc = new ParCollProperties + org.scalacheck.Test.checkProperties( + org.scalacheck.Test.Params( + rng = new java.util.Random(5134L), + testCallback = new ConsoleReporter(0), + workers = 1, + minSize = 0, + maxSize = 4000, + minSuccessfulTests = 5 + ), + pc + ) +} +*/ diff --git a/test/files/scalacheck/primitive-eqeq.scala b/test/scalacheck/primitive-eqeq.scala index 60fe63c207..fda8087bb0 100644 --- a/test/files/scalacheck/primitive-eqeq.scala +++ b/test/scalacheck/primitive-eqeq.scala @@ -2,7 +2,7 @@ import org.scalacheck._ import Prop._ import Gen._ -object Test extends Properties("==") { +object PrimitiveEqEqTest extends Properties("==") { def equalObjectsEqualHashcodes(x: Any, y: Any) = (x != y) || (x == y && x.## == y.##) // ticket #2087 diff --git a/test/files/scalacheck/quasiquotes/ArbitraryTreesAndNames.scala b/test/scalacheck/quasiquotes/ArbitraryTreesAndNames.scala index ab1056dd86..ab1056dd86 100644 --- a/test/files/scalacheck/quasiquotes/ArbitraryTreesAndNames.scala +++ b/test/scalacheck/quasiquotes/ArbitraryTreesAndNames.scala diff --git a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala b/test/scalacheck/quasiquotes/DefinitionConstructionProps.scala index 4ab8bb8531..4ab8bb8531 100644 --- a/test/files/scalacheck/quasiquotes/DefinitionConstructionProps.scala +++ b/test/scalacheck/quasiquotes/DefinitionConstructionProps.scala diff --git a/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala b/test/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala index 2c0e100b5a..2c0e100b5a 100644 --- a/test/files/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala +++ b/test/scalacheck/quasiquotes/DefinitionDeconstructionProps.scala diff --git a/test/files/scalacheck/quasiquotes/DeprecationProps.scala b/test/scalacheck/quasiquotes/DeprecationProps.scala index 8e1601cf9d..8e1601cf9d 100644 --- a/test/files/scalacheck/quasiquotes/DeprecationProps.scala +++ b/test/scalacheck/quasiquotes/DeprecationProps.scala diff --git a/test/files/scalacheck/quasiquotes/ErrorProps.scala b/test/scalacheck/quasiquotes/ErrorProps.scala index 0c24149372..0c24149372 100644 --- a/test/files/scalacheck/quasiquotes/ErrorProps.scala +++ b/test/scalacheck/quasiquotes/ErrorProps.scala diff --git a/test/files/scalacheck/quasiquotes/ForProps.scala b/test/scalacheck/quasiquotes/ForProps.scala index b14d345edd..b14d345edd 100644 --- a/test/files/scalacheck/quasiquotes/ForProps.scala +++ b/test/scalacheck/quasiquotes/ForProps.scala diff --git a/test/files/scalacheck/quasiquotes/LiftableProps.scala b/test/scalacheck/quasiquotes/LiftableProps.scala index a4c57ac359..a4c57ac359 100644 --- a/test/files/scalacheck/quasiquotes/LiftableProps.scala +++ b/test/scalacheck/quasiquotes/LiftableProps.scala diff --git a/test/files/scalacheck/quasiquotes/PatternConstructionProps.scala b/test/scalacheck/quasiquotes/PatternConstructionProps.scala index 7ed95fa984..7ed95fa984 100644 --- a/test/files/scalacheck/quasiquotes/PatternConstructionProps.scala +++ b/test/scalacheck/quasiquotes/PatternConstructionProps.scala diff --git a/test/files/scalacheck/quasiquotes/PatternDeconstructionProps.scala b/test/scalacheck/quasiquotes/PatternDeconstructionProps.scala index ad3266bcec..ad3266bcec 100644 --- a/test/files/scalacheck/quasiquotes/PatternDeconstructionProps.scala +++ b/test/scalacheck/quasiquotes/PatternDeconstructionProps.scala diff --git a/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala b/test/scalacheck/quasiquotes/QuasiquoteProperties.scala index 6132244227..614d3328a6 100644 --- a/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala +++ b/test/scalacheck/quasiquotes/QuasiquoteProperties.scala @@ -3,7 +3,7 @@ import scala.tools.reflect.{ToolBox, ToolBoxError} import scala.reflect.runtime.currentMirror import scala.reflect.runtime.universe._, Flag._, internal.reificationSupport.setSymbol -class QuasiquoteProperties(name: String) extends Properties(name) with ArbitraryTreesAndNames with Helpers +abstract class QuasiquoteProperties(name: String) extends Properties(name) with ArbitraryTreesAndNames with Helpers trait Helpers { /** Runs a code block and returns proof confirmation diff --git a/test/files/scalacheck/quasiquotes/RuntimeErrorProps.scala b/test/scalacheck/quasiquotes/RuntimeErrorProps.scala index 40fb42d63c..40fb42d63c 100644 --- a/test/files/scalacheck/quasiquotes/RuntimeErrorProps.scala +++ b/test/scalacheck/quasiquotes/RuntimeErrorProps.scala diff --git a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala b/test/scalacheck/quasiquotes/TermConstructionProps.scala index 409f07037e..409f07037e 100644 --- a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala +++ b/test/scalacheck/quasiquotes/TermConstructionProps.scala diff --git a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala b/test/scalacheck/quasiquotes/TermDeconstructionProps.scala index 07e8f3faac..07e8f3faac 100644 --- a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala +++ b/test/scalacheck/quasiquotes/TermDeconstructionProps.scala diff --git a/test/files/scalacheck/quasiquotes/TypeConstructionProps.scala b/test/scalacheck/quasiquotes/TypeConstructionProps.scala index 27ad4c50e9..27ad4c50e9 100644 --- a/test/files/scalacheck/quasiquotes/TypeConstructionProps.scala +++ b/test/scalacheck/quasiquotes/TypeConstructionProps.scala diff --git a/test/files/scalacheck/quasiquotes/TypeDeconstructionProps.scala b/test/scalacheck/quasiquotes/TypeDeconstructionProps.scala index 7572b27b52..7572b27b52 100644 --- a/test/files/scalacheck/quasiquotes/TypeDeconstructionProps.scala +++ b/test/scalacheck/quasiquotes/TypeDeconstructionProps.scala diff --git a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala b/test/scalacheck/quasiquotes/TypecheckedProps.scala index 07bff40f13..07bff40f13 100644 --- a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala +++ b/test/scalacheck/quasiquotes/TypecheckedProps.scala diff --git a/test/files/scalacheck/quasiquotes/UnliftableProps.scala b/test/scalacheck/quasiquotes/UnliftableProps.scala index 659b18edab..659b18edab 100644 --- a/test/files/scalacheck/quasiquotes/UnliftableProps.scala +++ b/test/scalacheck/quasiquotes/UnliftableProps.scala diff --git a/test/files/scalacheck/range.scala b/test/scalacheck/range.scala index ac24b52f8d..bbd7de2149 100644 --- a/test/files/scalacheck/range.scala +++ b/test/scalacheck/range.scala @@ -288,16 +288,6 @@ object TooLargeRange extends Properties("Too Large Range") { } } -object Test extends Properties("Range") { - import org.scalacheck.{ Test => STest } - - include(NormalRangeTest) - include(InclusiveRangeTest) - include(ByOneRangeTest) - include(InclusiveByOneRangeTest) - include(TooLargeRange) -} - /* Mini-benchmark def testRange(i: Int, j: Int, k: Int) = { var count = 0 diff --git a/test/scalacheck/redblacktree.scala b/test/scalacheck/redblacktree.scala new file mode 100644 index 0000000000..09c3839752 --- /dev/null +++ b/test/scalacheck/redblacktree.scala @@ -0,0 +1,247 @@ +package scala.collection.immutable.redblacktree + +import collection.immutable.{RedBlackTree => RB} +import org.scalacheck._ +import Prop._ +import Gen._ + +/* +Properties of a Red & Black Tree: + +A node is either red or black. +The root is black. (This rule is used in some definitions and not others. Since the +root can always be changed from red to black but not necessarily vice-versa this +rule has little effect on analysis.) +All leaves are black. +Both children of every red node are black. +Every simple path from a given node to any of its descendant leaves contains the same number of black nodes. +*/ + +abstract class RedBlackTreeTest extends Properties("RedBlackTree") { + def minimumSize = 0 + def maximumSize = 5 + + import RB._ + + def nodeAt[A](tree: Tree[String, A], n: Int): Option[(String, A)] = if (n < iterator(tree).size && n >= 0) + Some(iterator(tree).drop(n).next) + else + None + + def treeContains[A](tree: Tree[String, A], key: String) = iterator(tree).map(_._1) contains key + + def height(tree: Tree[_, _]): Int = if (tree eq null) 0 else (1 + math.max(height(tree.left), height(tree.right))) + + def mkTree(level: Int, parentIsBlack: Boolean = false, label: String = ""): Gen[Tree[String, Int]] = + if (level == 0) { + const(null) + } else { + for { + oddOrEven <- choose(0, 2) + tryRed = oddOrEven.sample.get % 2 == 0 // work around arbitrary[Boolean] bug + isRed = parentIsBlack && tryRed + nextLevel = if (isRed) level else level - 1 + left <- mkTree(nextLevel, !isRed, label + "L") + right <- mkTree(nextLevel, !isRed, label + "R") + } yield { + if (isRed) + RedTree(label + "N", 0, left, right) + else + BlackTree(label + "N", 0, left, right) + } + } + + def genTree = for { + depth <- choose(minimumSize, maximumSize + 1) + tree <- mkTree(depth) + } yield tree + + type ModifyParm + def genParm(tree: Tree[String, Int]): Gen[ModifyParm] + def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] + + def genInput: Gen[(Tree[String, Int], ModifyParm, Tree[String, Int])] = for { + tree <- genTree + parm <- genParm(tree) + } yield (tree, parm, modify(tree, parm)) +} + +trait RedBlackTreeInvariants { + self: RedBlackTreeTest => + + import RB._ + + def rootIsBlack[A](t: Tree[String, A]) = isBlack(t) + + def areAllLeavesBlack[A](t: Tree[String, A]): Boolean = t match { + case null => isBlack(t) + case ne => List(ne.left, ne.right) forall areAllLeavesBlack + } + + def areRedNodeChildrenBlack[A](t: Tree[String, A]): Boolean = t match { + case RedTree(_, _, left, right) => List(left, right) forall (t => isBlack(t) && areRedNodeChildrenBlack(t)) + case BlackTree(_, _, left, right) => List(left, right) forall areRedNodeChildrenBlack + case null => true + } + + def blackNodesToLeaves[A](t: Tree[String, A]): List[Int] = t match { + case null => List(1) + case BlackTree(_, _, left, right) => List(left, right) flatMap blackNodesToLeaves map (_ + 1) + case RedTree(_, _, left, right) => List(left, right) flatMap blackNodesToLeaves + } + + def areBlackNodesToLeavesEqual[A](t: Tree[String, A]): Boolean = t match { + case null => true + case ne => + ( + blackNodesToLeaves(ne).distinct.size == 1 + && areBlackNodesToLeavesEqual(ne.left) + && areBlackNodesToLeavesEqual(ne.right) + ) + } + + def orderIsPreserved[A](t: Tree[String, A]): Boolean = + iterator(t) zip iterator(t).drop(1) forall { case (x, y) => x._1 < y._1 } + + def heightIsBounded(t: Tree[_, _]): Boolean = height(t) <= (2 * (32 - Integer.numberOfLeadingZeros(count(t) + 2)) - 2) + + def setup(invariant: Tree[String, Int] => Boolean) = forAll(genInput) { case (tree, parm, newTree) => + invariant(newTree) + } + + property("root is black") = setup(rootIsBlack) + property("all leaves are black") = setup(areAllLeavesBlack) + property("children of red nodes are black") = setup(areRedNodeChildrenBlack) + property("black nodes are balanced") = setup(areBlackNodesToLeavesEqual) + property("ordering of keys is preserved") = setup(orderIsPreserved) + property("height is bounded") = setup(heightIsBounded) +} + +object TestInsert extends RedBlackTreeTest with RedBlackTreeInvariants { + import RB._ + + override type ModifyParm = Int + override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = choose(0, iterator(tree).size + 1) + override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = update(tree, generateKey(tree, parm), 0, true) + + def generateKey(tree: Tree[String, Int], parm: ModifyParm): String = nodeAt(tree, parm) match { + case Some((key, _)) => key.init.mkString + "MN" + case None => nodeAt(tree, parm - 1) match { + case Some((key, _)) => key.init.mkString + "RN" + case None => "N" + } + } + + property("update adds elements") = forAll(genInput) { case (tree, parm, newTree) => + treeContains(newTree, generateKey(tree, parm)) + } +} + +object TestModify extends RedBlackTreeTest { + import RB._ + + def newValue = 1 + override def minimumSize = 1 + override type ModifyParm = Int + override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = choose(0, iterator(tree).size) + override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = nodeAt(tree, parm) map { + case (key, _) => update(tree, key, newValue, true) + } getOrElse tree + + property("update modifies values") = forAll(genInput) { case (tree, parm, newTree) => + nodeAt(tree,parm) forall { case (key, _) => + iterator(newTree) contains (key, newValue) + } + } +} + +object TestDelete extends RedBlackTreeTest with RedBlackTreeInvariants { + import RB._ + + override def minimumSize = 1 + override type ModifyParm = Int + override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = choose(0, iterator(tree).size) + override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = nodeAt(tree, parm) map { + case (key, _) => delete(tree, key) + } getOrElse tree + + property("delete removes elements") = forAll(genInput) { case (tree, parm, newTree) => + nodeAt(tree, parm) forall { case (key, _) => + !treeContains(newTree, key) + } + } +} + +object TestRange extends RedBlackTreeTest with RedBlackTreeInvariants { + import RB._ + + override type ModifyParm = (Option[Int], Option[Int]) + override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = for { + from <- choose(0, iterator(tree).size) + to <- choose(0, iterator(tree).size) suchThat (from <=) + optionalFrom <- oneOf(Some(from), None, Some(from)) // Double Some(n) to get around a bug + optionalTo <- oneOf(Some(to), None, Some(to)) // Double Some(n) to get around a bug + } yield (optionalFrom, optionalTo) + + override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = { + val from = parm._1 flatMap (nodeAt(tree, _) map (_._1)) + val to = parm._2 flatMap (nodeAt(tree, _) map (_._1)) + rangeImpl(tree, from, to) + } + + property("range boundaries respected") = forAll(genInput) { case (tree, parm, newTree) => + val from = parm._1 flatMap (nodeAt(tree, _) map (_._1)) + val to = parm._2 flatMap (nodeAt(tree, _) map (_._1)) + ("lower boundary" |: (from forall ( key => keysIterator(newTree) forall (key <=)))) && + ("upper boundary" |: (to forall ( key => keysIterator(newTree) forall (key >)))) + } + + property("range returns all elements") = forAll(genInput) { case (tree, parm, newTree) => + val from = parm._1 flatMap (nodeAt(tree, _) map (_._1)) + val to = parm._2 flatMap (nodeAt(tree, _) map (_._1)) + val filteredTree = (keysIterator(tree) + .filter(key => from forall (key >=)) + .filter(key => to forall (key <)) + .toList) + filteredTree == keysIterator(newTree).toList + } +} + +object TestDrop extends RedBlackTreeTest with RedBlackTreeInvariants { + import RB._ + + override type ModifyParm = Int + override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = choose(0, iterator(tree).size) + override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = drop(tree, parm) + + property("drop") = forAll(genInput) { case (tree, parm, newTree) => + iterator(tree).drop(parm).toList == iterator(newTree).toList + } +} + +object TestTake extends RedBlackTreeTest with RedBlackTreeInvariants { + import RB._ + + override type ModifyParm = Int + override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = choose(0, iterator(tree).size) + override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = take(tree, parm) + + property("take") = forAll(genInput) { case (tree, parm, newTree) => + iterator(tree).take(parm).toList == iterator(newTree).toList + } +} + +object TestSlice extends RedBlackTreeTest with RedBlackTreeInvariants { + import RB._ + + override type ModifyParm = (Int, Int) + override def genParm(tree: Tree[String, Int]): Gen[ModifyParm] = for { + from <- choose(0, iterator(tree).size) + to <- choose(from, iterator(tree).size) + } yield (from, to) + override def modify(tree: Tree[String, Int], parm: ModifyParm): Tree[String, Int] = slice(tree, parm._1, parm._2) + + property("slice") = forAll(genInput) { case (tree, parm, newTree) => + iterator(tree).slice(parm._1, parm._2).toList == iterator(newTree).toList + } +} diff --git a/test/scaladoc/scalacheck/CommentFactoryTest.scala b/test/scalacheck/scaladoc/CommentFactoryTest.scala index d30b78087c..3a2b6a3bac 100644 --- a/test/scaladoc/scalacheck/CommentFactoryTest.scala +++ b/test/scalacheck/scaladoc/CommentFactoryTest.scala @@ -34,7 +34,7 @@ class Factory(val g: Global, val s: doc.Settings) parse(s, "", scala.tools.nsc.util.NoPosition, null).body } -object Test extends Properties("CommentFactory") { +object CommentFactoryTest extends Properties("CommentFactory") { val factory = { val settings = new doc.Settings((str: String) => {}) val reporter = new scala.tools.nsc.reporters.ConsoleReporter(settings) diff --git a/test/scaladoc/scalacheck/HtmlFactoryTest.scala b/test/scalacheck/scaladoc/HtmlFactoryTest.scala index ab2c058a03..a48b76c45a 100644 --- a/test/scaladoc/scalacheck/HtmlFactoryTest.scala +++ b/test/scalacheck/scaladoc/HtmlFactoryTest.scala @@ -22,7 +22,7 @@ object XMLUtil { } } -object Test extends Properties("HtmlFactory") { +object HtmlFactoryTest extends Properties("HtmlFactory") { final val RESOURCES = "test/scaladoc/resources/" diff --git a/test/scaladoc/scalacheck/IndexScriptTest.scala b/test/scalacheck/scaladoc/IndexScriptTest.scala index 61f462186d..e4efb69639 100644 --- a/test/scaladoc/scalacheck/IndexScriptTest.scala +++ b/test/scalacheck/scaladoc/IndexScriptTest.scala @@ -5,7 +5,7 @@ import scala.tools.nsc.doc import scala.tools.nsc.doc.html.page.IndexScript import java.net.{URLClassLoader, URLDecoder} -object Test extends Properties("IndexScript") { +object IndexScriptTest extends Properties("IndexScript") { def getClasspath = { // these things can be tricky diff --git a/test/files/scalacheck/scan.scala b/test/scalacheck/scan.scala index fc214d739c..4d2abafdef 100644 --- a/test/files/scalacheck/scan.scala +++ b/test/scalacheck/scan.scala @@ -2,10 +2,7 @@ import org.scalacheck._ import Prop._ import Gen._ - - - -object Test extends Properties("TraversableLike.scanLeft") { +object ScanTest extends Properties("TraversableLike.scanLeft") { property("scanLeft") = forAll { (xs: List[Int], z: Int) => { val sums = xs.scanLeft(z)(_ + _) (xs.size == 0) || sums.zip(sums.tail).map(x => x._2 - x._1) == xs diff --git a/test/files/scalacheck/substringTests.scala b/test/scalacheck/substringTests.scala index 76260b9dd2..df3d18be0b 100644 --- a/test/files/scalacheck/substringTests.scala +++ b/test/scalacheck/substringTests.scala @@ -1,7 +1,6 @@ import org.scalacheck._ - -object Test extends Properties("String") { +object SubstringTest extends Properties("String") { property("startsWith") = Prop.forAll((a: String, b: String) => (a+b).startsWith(a)) property("endsWith") = Prop.forAll((a: String, b: String) => (a+b).endsWith(b)) diff --git a/test/files/scalacheck/t2460.scala b/test/scalacheck/t2460.scala index ab2911447a..42ff3ecfe6 100644 --- a/test/files/scalacheck/t2460.scala +++ b/test/scalacheck/t2460.scala @@ -3,7 +3,7 @@ import org.scalacheck.Properties import org.scalacheck.{Test => SCTest} import org.scalacheck.Gen -object Test extends Properties("Regex : Ticket 2460") { +object SI2460Test extends Properties("Regex : Ticket 2460") { val vowel = Gen.oneOf("a", "z") diff --git a/test/files/scalacheck/t4147.scala b/test/scalacheck/t4147.scala index 72f6e9afd5..c58abb99f0 100644 --- a/test/files/scalacheck/t4147.scala +++ b/test/scalacheck/t4147.scala @@ -6,7 +6,7 @@ import org.scalacheck.Gen import collection.mutable -object Test extends Properties("Mutable TreeSet") { +object SI4147Test extends Properties("Mutable TreeSet") { val generator = Gen.listOfN(1000, Gen.chooseNum(0, 1000)) diff --git a/test/files/scalacheck/treemap.scala b/test/scalacheck/treemap.scala index f672637c57..6978ca3145 100644 --- a/test/files/scalacheck/treemap.scala +++ b/test/scalacheck/treemap.scala @@ -6,7 +6,7 @@ import Arbitrary._ import util._ import Buildable._ -object Test extends Properties("TreeMap") { +object TreeMapTest extends Properties("TreeMap") { def genTreeMap[A: Arbitrary: Ordering, B: Arbitrary]: Gen[TreeMap[A, B]] = for { keys <- listOf(arbitrary[A]) @@ -36,7 +36,7 @@ object Test extends Properties("TreeMap") { val values = (1 to highest).reverse val subject = TreeMap(values zip values: _*) val it = subject.iterator - try { while (it.hasNext) it.next; true } catch { case _ => false } + try { while (it.hasNext) it.next; true } catch { case _: Throwable => false } } property("sorted") = forAll { (subject: TreeMap[Int, String]) => (subject.size >= 3) ==> { diff --git a/test/files/scalacheck/treeset.scala b/test/scalacheck/treeset.scala index 4b9b77dd7e..ec6de40693 100644 --- a/test/files/scalacheck/treeset.scala +++ b/test/scalacheck/treeset.scala @@ -5,7 +5,7 @@ import Gen._ import Arbitrary._ import util._ -object Test extends Properties("TreeSet") { +object TreeSetTest extends Properties("TreeSet") { def genTreeSet[A: Arbitrary: Ordering]: Gen[TreeSet[A]] = for { elements <- listOf(arbitrary[A]) @@ -34,7 +34,7 @@ object Test extends Properties("TreeSet") { val values = (1 to highest).reverse val subject = TreeSet(values: _*) val it = subject.iterator - try { while (it.hasNext) it.next; true } catch { case _ => false } + try { while (it.hasNext) it.next; true } catch { case _: Throwable => false } } property("sorted") = forAll { (subject: TreeSet[Int]) => (subject.size >= 3) ==> { diff --git a/test/scaladoc/scalacheck/HtmlFactoryTest.flags b/test/scaladoc/scalacheck/HtmlFactoryTest.flags deleted file mode 100644 index b2264ec4f4..0000000000 --- a/test/scaladoc/scalacheck/HtmlFactoryTest.flags +++ /dev/null @@ -1 +0,0 @@ --encoding UTF-8
\ No newline at end of file diff --git a/versions.properties b/versions.properties index 83417bfbd5..ae903bfe6e 100644 --- a/versions.properties +++ b/versions.properties @@ -25,5 +25,3 @@ scala-asm.version=5.1.0-scala-1 # external modules, used internally (not shipped) partest.version.number=1.1.0 - -scalacheck.version.number=1.11.6 |