Skip to content

Commit

Permalink
Move tests to scalacheck.tests package.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdziuban committed Jul 6, 2023
1 parent 2530585 commit 7ab14ce
Show file tree
Hide file tree
Showing 31 changed files with 147 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import java.util.concurrent.TimeUnit

import Prop._
import Arbitrary._
import org.scalacheck.{Arbitrary, Gen, Prop, Properties}
import org.scalacheck.Prop._
import org.scalacheck.Arbitrary._

object ArbitrarySpecification extends Properties("Arbitrary") {
val genOptionUnits =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import java.time._
import java.time.temporal.ChronoUnit
Expand All @@ -16,7 +16,8 @@ import scala.util.Failure
import scala.util.Success
import scala.util.Try

import Gen._
import org.scalacheck.{Arbitrary, Gen, Prop, Properties}
import org.scalacheck.Gen._

object ChooseSpecification extends Properties("Choose") with time.OrderingVersionSpecific {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import org.scalacheck.{Arbitrary, Cogen, Prop, Properties}
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.Gen.listOfN
import org.scalacheck.GenSpecification.arbSeed
import org.scalacheck.Prop.forAll
import org.scalacheck.rng.Seed

Expand All @@ -22,6 +22,7 @@ import scala.collection.immutable.SortedSet
import scala.concurrent.duration.Duration
import scala.concurrent.duration.FiniteDuration
import scala.util.Try
import GenSpecification.arbSeed
import ScalaVersionSpecific._

object CogenSpecification extends Properties("Cogen") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import scala.util.Failure
import scala.util.Success
import scala.util.Try

import rng.Seed
import Gen._
import Prop.{forAll, forAllNoShrink, someFailing, noneFailing, sizedProp, secure, propBoolean}
import Arbitrary._
import Shrink._
import org.scalacheck.{Arbitrary, Cogen, Gen, Prop, Properties}
import org.scalacheck.rng.Seed
import org.scalacheck.Gen._
import org.scalacheck.Prop.{forAll, forAllNoShrink, someFailing, noneFailing, sizedProp, secure, propBoolean}
import org.scalacheck.Arbitrary._
import org.scalacheck.Shrink._

object GenSpecification extends Properties("Gen") with GenSpecificationVersionSpecific {

Expand Down Expand Up @@ -574,31 +575,31 @@ object GenSpecification extends Properties("Gen") with GenSpecificationVersionSp
forAllNoShrink(Gen.choose(1000000, 2000000)) { n =>
var i = 0
var sum = 0d
var seed = rng.Seed(n.toLong)
var seed = Seed(n.toLong)
while (i < n) {
val (d, s1) = seed.double
sum += d
i += 1
seed = s1
}
val avg = sum / n
(avg >= 0.49 && avg <= 0.51).labelImpl2(s"average = $avg")
s"average = $avg" |: avg >= 0.49 && avg <= 0.51
}

property("uniform long #209") = {
val scale = 1d / Long.MaxValue
forAllNoShrink(Gen.choose(1000000, 2000000)) { n =>
var i = 0
var sum = 0d
var seed = rng.Seed(n.toLong)
var seed = Seed(n.toLong)
while (i < n) {
val (l, s1) = seed.long
sum += math.abs(l).toDouble * scale
i += 1
seed = s1
}
val avg = sum / n
(avg >= 0.49 && avg <= 0.51).labelImpl2(s"average = $avg")
s"average = $avg" |: avg >= 0.49 && avg <= 0.51
}
}
////
Expand Down Expand Up @@ -651,7 +652,7 @@ object GenSpecification extends Properties("Gen") with GenSpecificationVersionSp
val s0 = (1 to 30).map(_ => g(params0, Seed.random())).toSet
val s1 = (1 to 30).map(_ => g(params1, Seed.random())).toSet
val s2 = (1 to 30).map(_ => g(params0, seed)).toSet
(s0.size > 1).labelImpl2(s"$s0") && (s1.size == 1).labelImpl2(s"$s1") && (s2.size == 1).labelImpl2(s"$s2")
(s"$s0" |: s0.size > 1) && (s"$s1" |: s1.size == 1) && (s"$s2" |: s2.size == 1)
}

property("arbitrary[Boolean] is deterministic") =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import org.scalacheck.{Prop, Properties}

object LazyPropertiesSpecification extends Properties("Properties.lazy registration") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import Prop.propBoolean
import org.scalacheck.{Gen, Prop, Properties, Test}
import org.scalacheck.Prop.propBoolean

object PropertyFilterSampleSpecification extends Properties("PropertyFilterSample") {

Expand Down Expand Up @@ -43,7 +44,7 @@ object PropertyFilterSpecification extends Properties("PropertyFilter") {

def props = actualNames.forall(expectedNames.contains)

(lengthProp && props).labelImpl2(diff(filter, actualNames, expectedNames))
(lengthProp && props) :| diff(filter, actualNames, expectedNames)
}

property("filter properties by predicate") =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import org.apache.commons.lang3.SerializationUtils

import java.io.Serializable

import util.SerializableCanBuildFroms._
import org.scalacheck.{Arbitrary, Cogen, Gen, Properties, Shrink}
import org.scalacheck.rng.Seed
import org.scalacheck.util.SerializableCanBuildFroms._

object SerializabilitySpecification extends Properties("Serializability") {

Expand Down Expand Up @@ -156,7 +158,7 @@ object SerializabilitySpecification extends Properties("Serializability") {
serializableShrink[List[(String, Int)]]("List[(String,Int)]")

property("Seed(1L)") = {
serializable(rng.Seed(1L))
serializable(Seed(1L))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import Prop.{forAll, propBoolean}
import Shrink.shrink
import org.scalacheck.Properties
import org.scalacheck.Prop.{forAll, propBoolean}
import org.scalacheck.Shrink.shrink
import ShrinkSpecification.shrinkClosure

/** @todo
Expand All @@ -25,14 +26,14 @@ object ShrinkSpecificationJVM extends Properties("Shrink JVM") {
property("non-empty list") = forAll { (l: List[Int]) =>
(!l.isEmpty && l != List(0)) ==> {
val ls = shrinkClosure(l)
(ls.contains(Nil) && ls.contains(List(0))).labelImpl2(ls.toList.toString)
ls.toList.toString |: (ls.contains(Nil) && ls.contains(List(0)))
}
}

property("xmap vector from list") = forAll { (v: Vector[Int]) =>
(!v.isEmpty && v != Vector(0)) ==> {
val vs = shrinkClosure(v)
(vs.contains(Vector.empty) && vs.contains(Vector(0))).labelImpl2(Vector(vs: _*).toString)
Vector(vs: _*).toString |: (vs.contains(Vector.empty) && vs.contains(Vector(0)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import org.scalacheck.Properties

object TestAll {
object ScalaCheckSpecification extends Properties("ScalaCheck") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import Gen._
import Prop._
import Test._
import Arbitrary._
import org.scalacheck.{Gen, Prop, Properties, Shrink, Test}
import org.scalacheck.Gen._
import org.scalacheck.Prop._
import org.scalacheck.Test._
import org.scalacheck.Arbitrary._
import org.scalacheck.rng.Seed

object TestSpecification extends Properties("Test") {

Expand Down Expand Up @@ -53,13 +55,11 @@ object TestSpecification extends Properties("Test") {
private def resultInvariant(f: (Test.Parameters, Test.Result) => Boolean): Prop =
forAll { (prms: Test.Parameters, p: Prop) =>
val r = Test.check(prms, p)
f(prms, r).labelImpl2(
s"${r.status}, s=${r.succeeded}, d=${r.discarded}, " +
s"minSuccessful=${prms.minSuccessfulTests}, " +
s"maxDiscardRatio=${prms.maxDiscardRatio}, " +
s"actualDiscardRatio=${r.discarded.toFloat / r.succeeded}, " +
s"workers=${prms.workers}"
)
s"${r.status}, s=${r.succeeded}, d=${r.discarded}, " +
s"minSuccessful=${prms.minSuccessfulTests}, " +
s"maxDiscardRatio=${prms.maxDiscardRatio}, " +
s"actualDiscardRatio=${r.discarded.toFloat / r.succeeded}, " +
s"workers=${prms.workers}" |: f(prms, r)
}

property("stopCondition") = resultInvariant { (prms, r) =>
Expand Down Expand Up @@ -112,8 +112,8 @@ object TestSpecification extends Properties("Test") {

property("propGenException") = forAll { (prms: Test.Parameters) =>
Test.check(prms, genException).status match {
case x: PropException => true.labelImpl2(x.toString)
case x => false.labelImpl2(x.toString)
case x: PropException => true :| x.toString
case x => false :| x.toString
}
}

Expand Down Expand Up @@ -148,8 +148,8 @@ object TestSpecification extends Properties("Test") {

property("Properties.overrideParameters overrides Test.Parameters") = {

val seed0 = rng.Seed.fromBase64("aaaaa_mr05Z_DCbd2PyUolC0h93iH1MQwIdnH2UuI4L=").get
val seed1 = rng.Seed.fromBase64("zzzzz_mr05Z_DCbd2PyUolC0h93iH1MQwIdnH2UuI4L=").get
val seed0 = Seed.fromBase64("aaaaa_mr05Z_DCbd2PyUolC0h93iH1MQwIdnH2UuI4L=").get
val seed1 = Seed.fromBase64("zzzzz_mr05Z_DCbd2PyUolC0h93iH1MQwIdnH2UuI4L=").get

val myProps = new Properties("MyProps") {
override def overrideParameters(prms: Test.Parameters): Test.Parameters =
Expand All @@ -170,7 +170,7 @@ object TestSpecification extends Properties("Test") {
}

property("initialSeed is used and then updated") = {
val seed = rng.Seed.fromBase64("aaaaa_mr05Z_DCbd2PyUolC0h93iH1MQwIdnH2UuI4L=").get
val seed = Seed.fromBase64("aaaaa_mr05Z_DCbd2PyUolC0h93iH1MQwIdnH2UuI4L=").get
val gen = Gen.choose(Int.MinValue, Int.MaxValue)
val expected = gen(Gen.Parameters.default, seed).get

Expand All @@ -187,13 +187,13 @@ object TestSpecification extends Properties("Test") {
val res = Test.check(prms, prop)
val n = xs.size
val unique = xs.toSet
val p0 = Prop(unique(expected)).labelImpl2(s"did not see $expected in $unique")
val p1 = Prop(unique.size > 1).labelImpl2(s"saw $n duplicate values: $unique")
val p0 = Prop(unique(expected)) :| s"did not see $expected in $unique"
val p1 = Prop(unique.size > 1) :| s"saw $n duplicate values: $unique"
p0 && p1
}

property("initialSeed is used and then updated when varying RNG spins") = {
val seed = rng.Seed.fromBase64("aaaaa_mr05Z_DCbd2PyUolC0h93iH1MQwIdnH2UuI4L=").get
val seed = Seed.fromBase64("aaaaa_mr05Z_DCbd2PyUolC0h93iH1MQwIdnH2UuI4L=").get
val gen = Gen.choose(Int.MinValue, Int.MaxValue)
val expected = gen(Gen.Parameters.default, seed).get

Expand All @@ -211,8 +211,8 @@ object TestSpecification extends Properties("Test") {
Test.check_(prms, prop)
val n = xs.size
val unique = xs.toSet
val p0 = Prop(unique(expected)).labelImpl2(s"did not see $expected in $unique")
val p1 = Prop(unique.size > 1).labelImpl2(s"saw $n duplicate values: $unique")
val p0 = Prop(unique(expected)) :| s"did not see $expected in $unique"
val p1 = Prop(unique.size > 1) :| s"saw $n duplicate values: $unique"
p0 && p1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck.commands
package scalacheck.tests.commands

import org.scalacheck.Arbitrary
import org.scalacheck.Gen
import org.scalacheck.Prop
import org.scalacheck.Prop.forAll
import org.scalacheck.Properties
import org.scalacheck.Shrink
import org.scalacheck.commands.Commands
import org.scalacheck.rng.Seed

import scala.reflect.ClassTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck.commands
package scalacheck.tests.commands

import org.scalacheck._
import org.scalacheck.commands._

object CommandsSpecification extends Properties("Commands") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests

import org.scalacheck.Prop.AnyOperators
import org.scalacheck.Prop.forAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck.example
package scalacheck.tests.example

import org.scalacheck._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
* There is NO WARRANTY. See the file LICENSE for the full text.
*/

package org.scalacheck
package scalacheck.tests
package rng

import scala.util.Try

import Prop.forAll
import Arbitrary.arbitrary
import org.scalacheck.{Arbitrary, Gen, Prop, Properties}
import org.scalacheck.rng.Seed
import org.scalacheck.Prop.forAll
import org.scalacheck.Arbitrary.arbitrary

object SeedSpecification extends Properties("Seed") {

Expand Down
Loading

0 comments on commit 7ab14ce

Please sign in to comment.