From 62372fc1de5c2b9e8844fc7b996e6f52ebce5956 Mon Sep 17 00:00:00 2001 From: David North Date: Thu, 7 Nov 2024 13:17:11 +0000 Subject: [PATCH] Instantiates a new dice each throw in unit tests --- .../src/test/scala/indigo/shared/dice/DiceTests.scala | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/indigo/indigo/src/test/scala/indigo/shared/dice/DiceTests.scala b/indigo/indigo/src/test/scala/indigo/shared/dice/DiceTests.scala index af134a9ac..a6be621a1 100644 --- a/indigo/indigo/src/test/scala/indigo/shared/dice/DiceTests.scala +++ b/indigo/indigo/src/test/scala/indigo/shared/dice/DiceTests.scala @@ -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) } @@ -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) } @@ -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) }