diff --git a/01.workspace/oxydice_lib/src/fun/mod.rs b/01.workspace/oxydice_lib/src/fun/mod.rs index e69de29..8b13789 100644 --- a/01.workspace/oxydice_lib/src/fun/mod.rs +++ b/01.workspace/oxydice_lib/src/fun/mod.rs @@ -0,0 +1 @@ + diff --git a/01.workspace/oxydice_lib/src/imp/dice_grab.rs b/01.workspace/oxydice_lib/src/imp/dice_grab.rs new file mode 100644 index 0000000..67ec895 --- /dev/null +++ b/01.workspace/oxydice_lib/src/imp/dice_grab.rs @@ -0,0 +1,17 @@ +use crate::*; + +impl Dice { + pub fn grab(dice: u16, sides: u16) -> Self { + let mut handful = Vec::::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 + } +} diff --git a/01.workspace/oxydice_lib/src/imp/mod.rs b/01.workspace/oxydice_lib/src/imp/mod.rs index e69de29..f8d11ea 100644 --- a/01.workspace/oxydice_lib/src/imp/mod.rs +++ b/01.workspace/oxydice_lib/src/imp/mod.rs @@ -0,0 +1 @@ +pub mod dice_grab; diff --git a/01.workspace/oxydice_lib/src/lib.rs b/01.workspace/oxydice_lib/src/lib.rs index 8784c5e..f3344ff 100644 --- a/01.workspace/oxydice_lib/src/lib.rs +++ b/01.workspace/oxydice_lib/src/lib.rs @@ -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; +} diff --git a/01.workspace/oxydice_lib/src/mcr/mod.rs b/01.workspace/oxydice_lib/src/mcr/mod.rs index e69de29..8b13789 100644 --- a/01.workspace/oxydice_lib/src/mcr/mod.rs +++ b/01.workspace/oxydice_lib/src/mcr/mod.rs @@ -0,0 +1 @@ + diff --git a/01.workspace/oxydice_lib/src/str/dice.rs b/01.workspace/oxydice_lib/src/str/dice.rs new file mode 100644 index 0000000..6e30395 --- /dev/null +++ b/01.workspace/oxydice_lib/src/str/dice.rs @@ -0,0 +1,17 @@ +use crate::*; + +#[derive(Debug, Default, PartialEq, Clone)] +pub struct O { + pub(crate) handful: Vec, +} + +// 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::*; +// } diff --git a/01.workspace/oxydice_lib/src/str/die.rs b/01.workspace/oxydice_lib/src/str/die.rs new file mode 100644 index 0000000..4524423 --- /dev/null +++ b/01.workspace/oxydice_lib/src/str/die.rs @@ -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 } + } +} diff --git a/01.workspace/oxydice_lib/src/str/mod.rs b/01.workspace/oxydice_lib/src/str/mod.rs index e69de29..177f396 100644 --- a/01.workspace/oxydice_lib/src/str/mod.rs +++ b/01.workspace/oxydice_lib/src/str/mod.rs @@ -0,0 +1,2 @@ +pub mod dice; +pub mod die; diff --git a/01.workspace/oxydice_lib/src/trt/mod.rs b/01.workspace/oxydice_lib/src/trt/mod.rs index e69de29..8b13789 100644 --- a/01.workspace/oxydice_lib/src/trt/mod.rs +++ b/01.workspace/oxydice_lib/src/trt/mod.rs @@ -0,0 +1 @@ + diff --git a/01.workspace/oxydice_lib/src/tst/dice_grab.rs b/01.workspace/oxydice_lib/src/tst/dice_grab.rs new file mode 100644 index 0000000..3dcf334 --- /dev/null +++ b/01.workspace/oxydice_lib/src/tst/dice_grab.rs @@ -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); + } + } +} diff --git a/01.workspace/oxydice_lib/src/tst/mod.rs b/01.workspace/oxydice_lib/src/tst/mod.rs index e69de29..f8d11ea 100644 --- a/01.workspace/oxydice_lib/src/tst/mod.rs +++ b/01.workspace/oxydice_lib/src/tst/mod.rs @@ -0,0 +1 @@ +pub mod dice_grab;