Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[allow(dead_code)]
- pub struct Guess {
- value: i32,
- }
- impl Guess {
- pub fn new(value: i32) -> Guess {
- if value < 1 {
- panic!(
- "Guess value must be less than or equal to 100, got {}.",
- value
- );
- } else if value > 100 {
- panic!(
- "Guess value must be greater than or equal to 1, got {}.",
- value
- );
- }
- Guess { value }
- }
- }
- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- #[should_panic(expected = "Guess value must be less than or equal to 100")]
- fn greater_than_100() {
- Guess::new(200);
- }
- }
Add Comment
Please, Sign In to add comment