Compare commits

..

2 Commits

Author SHA1 Message Date
projectmoon 297a8454f6 Avoid cloning when counting successes.
continuous-integration/drone/push Build is passing Details
2020-12-18 14:16:22 +00:00
projectmoon c9c80b974c Tests for dice pool formatting. 2020-12-17 21:14:43 +00:00
1 changed files with 31 additions and 3 deletions

View File

@ -190,12 +190,12 @@ impl DicePoolRoll {
} }
pub fn successes(&self) -> i32 { pub fn successes(&self) -> i32 {
let successes = self let successes: usize = self
.rolls .rolls
.iter() .iter()
.cloned() .filter(|&roll| *roll >= self.modifiers.success_on)
.filter(|&roll| roll >= self.modifiers.success_on)
.count(); .count();
i32::try_from(successes).unwrap_or(0) i32::try_from(successes).unwrap_or(0)
} }
@ -689,4 +689,32 @@ mod tests {
fmt_rolls(&result) fmt_rolls(&result)
); );
} }
#[test]
fn shows_more_than_10_dice_test() {
//Make sure we display more than 10 dice when below the display limit (15).
let result = DicePoolRoll {
modifiers: DicePoolModifiers::default(),
rolls: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
};
assert_eq!(
"1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14",
fmt_rolls(&result)
);
}
#[test]
fn shows_exactly_15_dice_test() {
//If we are at format limit (15), make sure all are shown
let result = DicePoolRoll {
modifiers: DicePoolModifiers::default(),
rolls: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
};
assert_eq!(
"1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15",
fmt_rolls(&result)
);
}
} }