Guest User

Untitled

a guest
Feb 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #[allow(dead_code)]
  2. pub struct Guess {
  3. value: i32,
  4. }
  5.  
  6. impl Guess {
  7. pub fn new(value: i32) -> Guess {
  8. if value < 1 {
  9. panic!(
  10. "Guess value must be less than or equal to 100, got {}.",
  11. value
  12. );
  13. } else if value > 100 {
  14. panic!(
  15. "Guess value must be greater than or equal to 1, got {}.",
  16. value
  17. );
  18. }
  19. Guess { value }
  20. }
  21. }
  22.  
  23. #[cfg(test)]
  24. mod tests {
  25. use super::*;
  26.  
  27. #[test]
  28. #[should_panic(expected = "Guess value must be less than or equal to 100")]
  29. fn greater_than_100() {
  30. Guess::new(200);
  31. }
  32. }
Add Comment
Please, Sign In to add comment