Match panic test against message
This commit is contained in:
parent
d12a578977
commit
60e8604567
1 changed files with 8 additions and 3 deletions
|
@ -9,7 +9,13 @@ pub struct Guess {
|
||||||
impl Guess {
|
impl Guess {
|
||||||
pub fn new(value: i32) -> Guess {
|
pub fn new(value: i32) -> Guess {
|
||||||
if value < 1 {
|
if value < 1 {
|
||||||
panic!("Guess value must be between 1 and 100, got {value}.");
|
panic!(
|
||||||
|
"Guess value must be greater than or equal to 1, got {value}."
|
||||||
|
);
|
||||||
|
} else if value > 100 {
|
||||||
|
panic!(
|
||||||
|
"Guess value must be less than or equal to 100, got {value}."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Guess { value }
|
Guess { value }
|
||||||
|
@ -56,9 +62,8 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[should_panic(expected = "less than or equal to 100")]
|
||||||
fn greater_than_100() {
|
fn greater_than_100() {
|
||||||
Guess::new(200);
|
Guess::new(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue