Changed to the Dice module to allow for specifying the number of dice and sides.

This commit is contained in:
Erik C. Thauvin 2022-03-27 22:45:26 -07:00
parent 61248387d8
commit 7bda64b5de
6 changed files with 46 additions and 59 deletions

View file

@ -35,13 +35,20 @@ package net.thauvin.erik.mobibot.modules
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.matches
import org.testng.annotations.Test
class DiceTest {
@Test
fun testWinLoseOrTie() {
assertThat(Dice.winLoseOrTie(6, 6), "6 vs. 6").isEqualTo(Dice.Result.TIE)
assertThat(Dice.winLoseOrTie(6, 5), "6 vs. 5").isEqualTo(Dice.Result.WIN)
assertThat(Dice.winLoseOrTie(5, 6), "5 vs. 6").isEqualTo(Dice.Result.LOSE)
fun testRoll() {
assertThat(Dice.roll(1, 1), "1d1").isEqualTo("\u00021\u0002")
assertThat(Dice.roll(2, 1), "2d1")
.isEqualTo("\u00021\u0002 + \u00021\u0002 = \u00022\u0002")
assertThat(Dice.roll(5, 1), "5d1")
.isEqualTo("\u00021\u0002 + \u00021\u0002 + \u00021\u0002 + \u00021\u0002 + \u00021\u0002 = \u00025\u0002")
assertThat(Dice.roll(2, 6), "2d6")
.matches("\u0002[1-6]\u0002 \\+ \u0002[1-6]\u0002 = \u0002[1-9][0-2]?\u0002".toRegex())
assertThat(Dice.roll(3, 7), "3d7")
.matches("\u0002[1-7]\u0002 \\+ \u0002[1-7]\u0002 \\+ \u0002[1-7]\u0002 = \u0002\\d{1,2}\u0002".toRegex())
}
}