-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating NumericGenerator to use choose instead of chooseNum. This wi…
…ll cause the generated values not to be weighted. Added tests to ensure none of the numeric generators are weighted.
- Loading branch information
Showing
2 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...om/github/fulrich/testcharged/generators/numerics/NumericGeneratorDistributionUTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.fulrich.testcharged.generators.numerics | ||
|
||
import org.scalacheck.Gen | ||
import org.scalacheck.Gen.Choose | ||
import org.scalatest.{FunSuite, Matchers} | ||
import org.scalatest.prop.GeneratorDrivenPropertyChecks | ||
|
||
|
||
class NumericGeneratorDistributionUTest extends FunSuite with Matchers with GeneratorDrivenPropertyChecks { | ||
|
||
test("The double generator does not weight extremities") { | ||
ensureExtremitiesNotWeighted(DoubleGenerators) | ||
} | ||
|
||
test("The integer generator does not weight extremities") { | ||
ensureExtremitiesNotWeighted(IntGenerators) | ||
} | ||
|
||
test("The long generator does not weight extremities") { | ||
ensureExtremitiesNotWeighted(LongGenerators) | ||
} | ||
|
||
test("The float generator does not weight extremities") { | ||
ensureExtremitiesNotWeighted(FloatGenerators) | ||
} | ||
|
||
test("The short generator does not weight extremities") { | ||
ensureExtremitiesNotWeighted(ShortGenerators) | ||
} | ||
|
||
def ensureExtremitiesNotWeighted[A : Choose](generator: NumericGenerator[A])(implicit numeric: Numeric[A]): Unit = { | ||
val sizeOfList: Int = 100 | ||
val fivePercent: Int = (sizeOfList * 0.05).toInt | ||
val listGenerator: Gen[Seq[A]] = Gen.listOfN(sizeOfList, generator.default.default) | ||
|
||
forAll(listGenerator) { generatedNumerics => | ||
generatedNumerics.count(_ == generator.DefaultMaximum) should be < fivePercent | ||
generatedNumerics.count(_ == numeric.negate(generator.DefaultMaximum)) should be < fivePercent | ||
} | ||
} | ||
} |