From 1d5a731812f89811b0b17480f38d68e23d85227c Mon Sep 17 00:00:00 2001 From: realaravinth Date: Tue, 2 Mar 2021 12:01:15 +0530 Subject: [PATCH] tests and updated error type --- src/defense.rs | 14 +++++++++++++- src/errors.rs | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/defense.rs b/src/defense.rs index f676fcc..92d6f5c 100644 --- a/src/defense.rs +++ b/src/defense.rs @@ -102,7 +102,7 @@ impl LevelBuilder { /// build Level struct pub fn build(&mut self) -> CaptchaResult { if self.visitor_threshold.is_none() { - Err(CaptchaError::SetVisitorCount) + Err(CaptchaError::SetVisitorThreshold) } else if self.difficulty_factor.is_none() { Err(CaptchaError::SetDifficultyFactor) } else { @@ -248,6 +248,18 @@ mod tests { LevelBuilder::default().difficulty_factor(0), Err(CaptchaError::DifficultyFactorZero) ); + + assert_eq!( + LevelBuilder::default() + .difficulty_factor(1) + .unwrap() + .build(), + Err(CaptchaError::SetVisitorThreshold) + ); + assert_eq!( + LevelBuilder::default().visitor_threshold(10).build(), + Err(CaptchaError::SetDifficultyFactor) + ); } #[test] diff --git a/src/errors.rs b/src/errors.rs index 28d3f0e..0ef2d52 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -38,9 +38,9 @@ pub enum CaptchaError { #[display(fmt = "Set difficulty factor")] SetDifficultyFactor, - /// Visitor count must be set - #[display(fmt = "Set visitor count")] - SetVisitorCount, + /// Visitor threshold must be set + #[display(fmt = "Set visitor threshold")] + SetVisitorThreshold, /// Visitor count must be Unique #[display(fmt = "Duplicate visitor count")]