Guest User

Untitled

a guest
Apr 25th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #[derive(Debug)]
  2. pub struct Rectangle {
  3. length: u32,
  4. width: u32,
  5. }
  6.  
  7. impl Rectangle {
  8. pub fn can_hold(&self, other: &Rectangle) -> bool {
  9. self.length < other.length && self.width > other.width
  10. }
  11. }
  12.  
  13. #[cfg(test)]
  14. mod tests {
  15. use super::Rectangle;
  16.  
  17. #[test]
  18. fn exploration() {
  19. assert_eq!(2 + 2, 4);
  20. }
  21.  
  22. #[test]
  23. fn test_number_two() {
  24. let larger = Rectangle {
  25. width: 7,
  26. length: 8,
  27. };
  28.  
  29. let smaller = Rectangle {
  30. width: 5,
  31. length: 6,
  32. };
  33.  
  34. //panic!(format!("{}", smaller.can_hold(&larger)));
  35. assert!(!smaller.can_hold(&larger));
  36. }
  37.  
  38.  
  39. #[test]
  40. fn larger_can_hold_smaller() {
  41. let larger = Rectangle { length: 8, width: 7 };
  42. let smaller = Rectangle { length: 5, width: 1 };
  43.  
  44. assert!(larger.can_hold(&smaller));
  45. }
  46. }
Add Comment
Please, Sign In to add comment