feat: add grab and and_grab methods to dice
This commit is contained in:
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
17
01.workspace/oxydice_lib/src/imp/dice_grab.rs
Normal file
17
01.workspace/oxydice_lib/src/imp/dice_grab.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::*;
|
||||
|
||||
impl Dice {
|
||||
pub fn grab(dice: u16, sides: u16) -> Self {
|
||||
let mut handful = Vec::<Die>::new();
|
||||
for _ in 1..=dice {
|
||||
handful.push(Die::new(sides));
|
||||
}
|
||||
Self { handful }
|
||||
}
|
||||
pub fn and_grab(mut self, dice: u16, sides: u16) -> Self {
|
||||
for _ in 1..=dice {
|
||||
self.handful.push(Die::new(sides));
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod dice_grab;
|
||||
|
||||
@@ -6,3 +6,10 @@ mod mcr;
|
||||
mod str;
|
||||
mod trt;
|
||||
mod tst;
|
||||
|
||||
pub(crate) use crate::str::dice::O as Dice;
|
||||
pub(crate) use crate::str::die::O as Die;
|
||||
|
||||
pub mod dice {
|
||||
pub use crate::str::dice::O as Dice;
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
17
01.workspace/oxydice_lib/src/str/dice.rs
Normal file
17
01.workspace/oxydice_lib/src/str/dice.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::*;
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Clone)]
|
||||
pub struct O {
|
||||
pub(crate) handful: Vec<Die>,
|
||||
}
|
||||
|
||||
// impl std::fmt::Display for O {
|
||||
// fn fmt(&self, _f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
||||
// todo!();
|
||||
// }
|
||||
// }
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod unit_tests {
|
||||
// use super::*;
|
||||
// }
|
||||
12
01.workspace/oxydice_lib/src/str/die.rs
Normal file
12
01.workspace/oxydice_lib/src/str/die.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use crate::*;
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Clone)]
|
||||
pub struct O {
|
||||
pub(crate) sides: u16,
|
||||
}
|
||||
|
||||
impl Die {
|
||||
pub fn new(sides: u16) -> Self {
|
||||
Self { sides }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod dice;
|
||||
pub mod die;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
28
01.workspace/oxydice_lib/src/tst/dice_grab.rs
Normal file
28
01.workspace/oxydice_lib/src/tst/dice_grab.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::*;
|
||||
#[test]
|
||||
pub fn grab_should_set_correct_number_of_dice() {
|
||||
let dice = Dice::grab(3, 6);
|
||||
assert_eq!(dice.handful.len(), 3);
|
||||
}
|
||||
#[test]
|
||||
pub fn grab_should_set_correct_number_of_sides() {
|
||||
let dice = Dice::grab(3, 6);
|
||||
for idx in 0..=2 {
|
||||
assert_eq!(dice.handful[idx].sides, 6);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn and_grab_should_add_correct_number_of_dice() {
|
||||
let dice = Dice::grab(3, 6).and_grab(2, 8);
|
||||
assert_eq!(dice.handful.len(), 5);
|
||||
}
|
||||
#[test]
|
||||
fn and_grab_should_set_correct_number_of_sides() {
|
||||
let dice = Dice::grab(3, 6).and_grab(2, 8);
|
||||
for idx in 3..4 {
|
||||
assert_eq!(dice.handful[idx].sides, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod dice_grab;
|
||||
|
||||
Reference in New Issue
Block a user