forked from bot/tmp2
tests and updated error type
This commit is contained in:
parent
a884edf2f2
commit
1d5a731812
|
@ -102,7 +102,7 @@ impl LevelBuilder {
|
||||||
/// build Level struct
|
/// build Level struct
|
||||||
pub fn build(&mut self) -> CaptchaResult<Level> {
|
pub fn build(&mut self) -> CaptchaResult<Level> {
|
||||||
if self.visitor_threshold.is_none() {
|
if self.visitor_threshold.is_none() {
|
||||||
Err(CaptchaError::SetVisitorCount)
|
Err(CaptchaError::SetVisitorThreshold)
|
||||||
} else if self.difficulty_factor.is_none() {
|
} else if self.difficulty_factor.is_none() {
|
||||||
Err(CaptchaError::SetDifficultyFactor)
|
Err(CaptchaError::SetDifficultyFactor)
|
||||||
} else {
|
} else {
|
||||||
|
@ -248,6 +248,18 @@ mod tests {
|
||||||
LevelBuilder::default().difficulty_factor(0),
|
LevelBuilder::default().difficulty_factor(0),
|
||||||
Err(CaptchaError::DifficultyFactorZero)
|
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]
|
#[test]
|
||||||
|
|
|
@ -38,9 +38,9 @@ pub enum CaptchaError {
|
||||||
#[display(fmt = "Set difficulty factor")]
|
#[display(fmt = "Set difficulty factor")]
|
||||||
SetDifficultyFactor,
|
SetDifficultyFactor,
|
||||||
|
|
||||||
/// Visitor count must be set
|
/// Visitor threshold must be set
|
||||||
#[display(fmt = "Set visitor count")]
|
#[display(fmt = "Set visitor threshold")]
|
||||||
SetVisitorCount,
|
SetVisitorThreshold,
|
||||||
|
|
||||||
/// Visitor count must be Unique
|
/// Visitor count must be Unique
|
||||||
#[display(fmt = "Duplicate visitor count")]
|
#[display(fmt = "Duplicate visitor count")]
|
||||||
|
|
Loading…
Reference in New Issue