Skip to content

Commit

Permalink
Instantiates a new dice each throw in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hobnob committed Nov 7, 2024
1 parent 68a04b7 commit 62372fc
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ class DiceTests extends munit.FunSuite {
test("all dice rolls have an approximately uniform distribution") {
val diceSides = 63
val numRuns = 200_000_000
val dice = Dice.diceSidesN(diceSides, 0)
val expectedDistribution = 1.0 / diceSides
val generatedNums =
Array
.range(0, numRuns)
.foldLeft(SortedMap[Int, Int]()) { (acc, _) =>
val roll = dice.roll
val roll = Dice.diceSidesN(diceSides, scala.util.Random.nextLong()).roll
acc.updated(roll, acc.getOrElse(roll, 0) + 1)
}

Expand All @@ -93,13 +92,12 @@ class DiceTests extends munit.FunSuite {
val diceSides = 63
val halfSides = Math.floor(diceSides / 2.0).toInt
val numRuns = 200_000_000
val dice = Dice.diceSidesN(diceSides, 0)
val expectedDistribution = 1.0 / halfSides
val generatedNums =
Array
.range(0, numRuns)
.foldLeft(SortedMap[Int, Int]()) { (acc, _) =>
val roll = dice.rollRange(halfSides, diceSides)
val roll = Dice.diceSidesN(diceSides, scala.util.Random.nextLong()).rollRange(halfSides, diceSides)
acc.updated(roll, acc.getOrElse(roll, 0) + 1)
}

Expand All @@ -120,13 +118,12 @@ class DiceTests extends munit.FunSuite {

test("all dice rolls in rollRange(1, 4) have an approximately uniform distribution") {
val numRuns = 200_000_000
val dice = Dice.diceSidesN(4, 0)
val expectedDistribution = 0.25
val generatedNums =
Array
.range(0, numRuns)
.foldLeft(SortedMap[Int, Int]()) { (acc, _) =>
val roll = dice.rollRange(1, 4)
val roll = Dice.diceSidesN(4, scala.util.Random.nextLong()).rollRange(1, 4)
acc.updated(roll, acc.getOrElse(roll, 0) + 1)
}

Expand Down

0 comments on commit 62372fc

Please sign in to comment.