feat: add Die and Dice structs with grab and and_grab methods

This commit is contained in:
2025-11-15 12:01:24 +01:00
parent ab757e3080
commit 589c25cdcd
12 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn dice_grab_should_create_a_new_handful_of_dice() {
let dice_handful = Dice::grab(3, 6);
assert_eq!(dice_handful.handful.len(), 3);
for die in dice_handful.handful {
assert_eq!(die.sides, 6);
}
}
#[test]
fn test_dice_and_grab_should_add_more_dice_to_handful() {
let initial_dice = Dice::grab(2, 6);
let initial_count = initial_dice.handful.len();
let new_dice_handful = initial_dice.and_grab(2, 8);
assert_eq!(new_dice_handful.handful.len(), initial_count + 2);
// Check the sides of the newly added dice
for i in initial_count..new_dice_handful.handful.len() {
assert_eq!(new_dice_handful.handful[i].sides, 8);
}
}
}

View File

@@ -0,0 +1,2 @@
pub mod dice_grab;