chore: scrap and restart project
This commit is contained in:
@@ -1,6 +0,0 @@
|
|||||||
use oxydice_lib::*;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut dice = dice::Dice::grab(3, 6);
|
|
||||||
dice.roll();
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
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,
|
|
||||||
..Self::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn and_grab(mut self, dice: u16, sides: u16) -> Self {
|
|
||||||
for _ in 1..=dice {
|
|
||||||
self.handful.push(Die::new(sides));
|
|
||||||
}
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
use crate::*;
|
|
||||||
|
|
||||||
impl Dice {
|
|
||||||
pub fn roll(&mut self) {
|
|
||||||
self.result.die_results.clear();
|
|
||||||
for die in &self.handful {
|
|
||||||
self.result.die_results.push(die.roll());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
use crate::*;
|
|
||||||
|
|
||||||
impl Die {
|
|
||||||
pub fn new(sides: u16) -> Die {
|
|
||||||
Self { sides }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
use crate::*;
|
|
||||||
|
|
||||||
impl Die {
|
|
||||||
pub fn roll(&self) -> u16 {
|
|
||||||
let mut rng = rand::rng();
|
|
||||||
rng.random_range(0..self.sides)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
pub mod dice_grab;
|
|
||||||
pub mod dice_roll;
|
|
||||||
pub mod die_new;
|
|
||||||
pub mod die_roll;
|
|
||||||
|
|||||||
@@ -1,18 +1,8 @@
|
|||||||
use std::*;
|
use std::*;
|
||||||
|
|
||||||
use rand::*;
|
|
||||||
|
|
||||||
mod fun;
|
mod fun;
|
||||||
mod imp;
|
mod imp;
|
||||||
mod mcr;
|
mod mcr;
|
||||||
mod str;
|
mod str;
|
||||||
mod trt;
|
mod trt;
|
||||||
mod tst;
|
mod tst;
|
||||||
|
|
||||||
pub(crate) use crate::str::dice::O as Dice;
|
|
||||||
pub(crate) use crate::str::die::O as Die;
|
|
||||||
pub(crate) use crate::str::roll_result::O as RollResult;
|
|
||||||
|
|
||||||
pub mod dice {
|
|
||||||
pub use crate::str::dice::O as Dice;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
use crate::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Clone)]
|
|
||||||
pub struct O {
|
|
||||||
pub(crate) handful: Vec<Die>,
|
|
||||||
pub(crate) result: RollResult,
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
use crate::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Clone)]
|
|
||||||
pub struct O {
|
|
||||||
pub(crate) sides: u16,
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
pub mod dice;
|
|
||||||
pub mod die;
|
|
||||||
pub mod roll_result;
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
use crate::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Clone)]
|
|
||||||
pub struct O {
|
|
||||||
pub(crate) die_results: Vec<u16>,
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
|
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
#[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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::*;
|
|
||||||
#[test]
|
|
||||||
pub fn dice_roll_should_yield_always_the_proper_number_of_result() {
|
|
||||||
let mut dice = Dice::grab(3, 6);
|
|
||||||
for _ in 1..=1000 {
|
|
||||||
dice.roll();
|
|
||||||
assert_eq!(dice.result.die_results.len(), 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
pub fn dice_roll_should_yield_valid_results() {
|
|
||||||
let mut dice = Dice::grab(3, 6);
|
|
||||||
for _ in 1..=10000 {
|
|
||||||
dice.roll();
|
|
||||||
assert!(dice.result.die_results[0] < 6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
pub mod dice_grab;
|
|
||||||
pub mod dice_roll;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user