Skip to content

Commit 0a766ee

Browse files
committed
Fix minor bug where numeric dice strings were not correctly setting diceModsNumber to 1.
1 parent 270b3f3 commit 0a766ee

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ezdice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function roll(string $diceStr): int|false
8787
if (is_numeric($diceStr)) {
8888
$this->total = (int)$diceStr;
8989
$this->modifier = $this->total;
90+
$this->diceModsNumber = 1;
9091
return $this->total;
9192
}
9293

test.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,33 @@ function testDropMultipleHighestDice() {
246246
assertEquals(2, $droppedCount);
247247
}
248248

249+
function testGetDiceModsNumber() {
250+
$ezd = new EZDice();
251+
$ezd->roll('');
252+
assertEquals(0, $ezd->getDiceGroupNumber());
253+
assertEquals(0, $ezd->getDiceModsNumber());
254+
255+
$ezd->roll('42');
256+
assertEquals(0, $ezd->getDiceGroupNumber());
257+
assertEquals(1, $ezd->getDiceModsNumber());
258+
259+
$ezd->roll('d6+2d4');
260+
assertEquals(2, $ezd->getDiceGroupNumber());
261+
assertEquals(0, $ezd->getDiceModsNumber());
262+
263+
$ezd->roll('1d6+2d4+5');
264+
assertEquals(2, $ezd->getDiceGroupNumber());
265+
assertEquals(1, $ezd->getDiceModsNumber());
266+
267+
$ezd->roll('1d6+2d4+5+10');
268+
assertEquals(2, $ezd->getDiceGroupNumber());
269+
assertEquals(2, $ezd->getDiceModsNumber());
270+
271+
$ezd->roll('1d6+2d4+5+10-3-1d%');
272+
assertEquals(3, $ezd->getDiceGroupNumber());
273+
assertEquals(3, $ezd->getDiceModsNumber());
274+
}
275+
249276
// Run tests
250277
$startTime = microtime(true);
251278
for ($i = 0; $i < TEST_RUNS; $i++) {
@@ -269,6 +296,7 @@ function testDropMultipleHighestDice() {
269296
testStrContainsDice();
270297
testStrIsStrictlyDice();
271298
testRollEmptyString();
299+
testGetDiceModsNumber();
272300

273301
echo "All tests passed.\n";
274302
echo "Time taken: " . ($endTime - $startTime) . " seconds.\n";

0 commit comments

Comments
 (0)