diff --git a/modules/scalacheck/src/weaver/scalacheck/CheckConfig.scala b/modules/scalacheck/src/weaver/scalacheck/CheckConfig.scala index 78c05283..3be56e4a 100644 --- a/modules/scalacheck/src/weaver/scalacheck/CheckConfig.scala +++ b/modules/scalacheck/src/weaver/scalacheck/CheckConfig.scala @@ -3,68 +3,121 @@ package scalacheck import org.scalacheck.rng.Seed -sealed abstract class CheckConfig private { outer => +final class CheckConfig( + val minimumSuccessful: Int, + val maximumDiscardRatio: Int, + val maximumGeneratorSize: Int, + val perPropertyParallelism: Int, + val initialSeed: Option[Seed]) extends Product with Serializable { + assert(maximumDiscardRatio >= 0) + assert(maximumDiscardRatio <= 100) + assert(minimumSuccessful > 0) - val minimumSuccessful: Int - def withMinimumSuccessful(minimumSuccessful: Int): CheckConfig = - cpy(minimumSuccessful0 = minimumSuccessful) + def maximumDiscarded = minimumSuccessful * maximumDiscardRatio / 100 - val maximumDiscardRatio: Int - def withMaximumDiscardRatio(maximumDiscardRatio: Int): CheckConfig = - cpy(maximumDiscardRatio0 = maximumDiscardRatio) + def withMinimumSuccessful(minimumSuccessful: Int) = new CheckConfig( + minimumSuccessful = minimumSuccessful, + maximumDiscardRatio = this.maximumDiscardRatio, + maximumGeneratorSize = this.maximumGeneratorSize, + perPropertyParallelism = this.perPropertyParallelism, + initialSeed = this.initialSeed + ) - val maximumGeneratorSize: Int - def withMaximumGeneratorSize(maximumGeneratorSize: Int): CheckConfig = - cpy(maximumGeneratorSize0 = maximumGeneratorSize) + def withMaximumDiscardRatio(maximumDiscardRatio: Int) = new CheckConfig( + minimumSuccessful = this.minimumSuccessful, + maximumDiscardRatio = maximumDiscardRatio, + maximumGeneratorSize = this.maximumGeneratorSize, + perPropertyParallelism = this.perPropertyParallelism, + initialSeed = this.initialSeed + ) - val perPropertyParallelism: Int - def withPerPropertyParallelism(perPropertyParallelism: Int): CheckConfig = - cpy(perPropertyParallelism0 = perPropertyParallelism) + def withMaximumGeneratorSize(maximumGeneratorSize: Int) = new CheckConfig( + minimumSuccessful = this.minimumSuccessful, + maximumDiscardRatio = this.maximumDiscardRatio, + maximumGeneratorSize = maximumGeneratorSize, + perPropertyParallelism = this.perPropertyParallelism, + initialSeed = this.initialSeed + ) - val initialSeed: Option[Seed] - def withInitialSeed(initialSeed: Option[Seed]): CheckConfig = - cpy(initialSeed0 = initialSeed) + def withPerPropertyParallelism(perPropertyParallelism: Int) = new CheckConfig( + minimumSuccessful = this.minimumSuccessful, + maximumDiscardRatio = this.maximumDiscardRatio, + maximumGeneratorSize = this.maximumGeneratorSize, + perPropertyParallelism = perPropertyParallelism, + initialSeed = this.initialSeed + ) - def maximumDiscarded = minimumSuccessful * maximumDiscardRatio / 100 + def withInitialSeed(initialSeed: Option[Seed]) = new CheckConfig( + minimumSuccessful = this.minimumSuccessful, + maximumDiscardRatio = this.maximumDiscardRatio, + maximumGeneratorSize = this.maximumGeneratorSize, + perPropertyParallelism = this.perPropertyParallelism, + initialSeed = initialSeed + ) - private[this] def cpy( - minimumSuccessful0: Int = outer.minimumSuccessful, - maximumDiscardRatio0: Int = outer.maximumDiscardRatio, - maximumGeneratorSize0: Int = outer.maximumGeneratorSize, - perPropertyParallelism0: Int = outer.perPropertyParallelism, - initialSeed0: Option[Seed] = outer.initialSeed): CheckConfig = - new CheckConfig { - val minimumSuccessful: Int = minimumSuccessful0 - val maximumDiscardRatio: Int = maximumDiscardRatio0 - val maximumGeneratorSize: Int = maximumGeneratorSize0 - val perPropertyParallelism: Int = perPropertyParallelism0 - val initialSeed: Option[Seed] = initialSeed0 - } -} + override def toString: String = { + val b = new StringBuilder("CheckConfig(") + b.append(String.valueOf(this.minimumSuccessful)) + b.append(", ") + b.append(String.valueOf(this.maximumDiscardRatio)) + b.append(", ") + b.append(String.valueOf(this.maximumGeneratorSize)) + b.append(", ") + b.append(String.valueOf(this.perPropertyParallelism)) + b.append(", ") + b.append(String.valueOf(this.initialSeed)) + b.append(")") + b.toString() + } -object CheckConfig { - val default: CheckConfig = new CheckConfig { - val minimumSuccessful = 80 - val maximumDiscardRatio = 5 - val maximumGeneratorSize = 100 - val perPropertyParallelism = 10 - val initialSeed = None + override def canEqual(obj: Any): Boolean = + obj != null && obj.isInstanceOf[CheckConfig] + + override def equals(obj: Any): Boolean = canEqual(obj) && { + val other = obj.asInstanceOf[CheckConfig] + this.minimumSuccessful == other.minimumSuccessful && this.maximumDiscardRatio == other.maximumDiscardRatio && this.maximumGeneratorSize == other.maximumGeneratorSize && + this.perPropertyParallelism == other.perPropertyParallelism && this.initialSeed == other.initialSeed } - def apply( - minimumSuccessful0: Int, - maximumDiscardRatio0: Int, - maximumGeneratorSize0: Int, - perPropertyParallelism0: Int, - initialSeed0: Option[Seed]): CheckConfig = new CheckConfig { - assert(maximumDiscardRatio0 >= 0) - assert(maximumDiscardRatio0 <= 100) - assert(minimumSuccessful0 > 0) - val minimumSuccessful = minimumSuccessful0 - val maximumDiscardRatio = maximumDiscardRatio0 - val maximumGeneratorSize = maximumGeneratorSize0 - val perPropertyParallelism = perPropertyParallelism0 - val initialSeed = initialSeed0 + override def hashCode: Int = { + var code = 17 + "CheckConfig".## + code = 37 * code + this.minimumSuccessful.## + code = 37 * code + this.maximumDiscardRatio.## + code = 37 * code + this.maximumGeneratorSize.## + code = 37 * code + this.perPropertyParallelism.## + code = 37 * code + this.initialSeed.## + 37 * code } + override def productPrefix: String = "CheckConfig" + + override def productArity: Int = 5 + + override def productElement(n: Int): Any = n match { + case 0 => this.minimumSuccessful + case 1 => this.maximumDiscardRatio + case 2 => this.maximumGeneratorSize + case 3 => this.perPropertyParallelism + case 4 => this.initialSeed + case n => throw new IndexOutOfBoundsException(n.toString) + } +} + +object CheckConfig { + def default: CheckConfig = CheckConfig(minimumSuccessful = 80, + maximumDiscardRatio = 5, + maximumGeneratorSize = 100, + perPropertyParallelism = 10, + initialSeed = None) + def apply( + minimumSuccessful: Int, + maximumDiscardRatio: Int, + maximumGeneratorSize: Int, + perPropertyParallelism: Int, + initialSeed: Option[Seed]): CheckConfig = + new CheckConfig(minimumSuccessful, + maximumDiscardRatio, + maximumGeneratorSize, + perPropertyParallelism, + initialSeed) }