Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)]
- pub struct Rectangle {
- length: u32,
- width: u32,
- }
- impl Rectangle {
- pub fn can_hold(&self, other: &Rectangle) -> bool {
- self.length < other.length && self.width > other.width
- }
- }
- #[cfg(test)]
- mod tests {
- use super::Rectangle;
- #[test]
- fn exploration() {
- assert_eq!(2 + 2, 4);
- }
- #[test]
- fn test_number_two() {
- let larger = Rectangle {
- width: 7,
- length: 8,
- };
- let smaller = Rectangle {
- width: 5,
- length: 6,
- };
- //panic!(format!("{}", smaller.can_hold(&larger)));
- assert!(!smaller.can_hold(&larger));
- }
- #[test]
- fn larger_can_hold_smaller() {
- let larger = Rectangle { length: 8, width: 7 };
- let smaller = Rectangle { length: 5, width: 1 };
- assert!(larger.can_hold(&smaller));
- }
- }
Add Comment
Please, Sign In to add comment