Add tests for the rectangles project

This commit is contained in:
Manuel Thalmann 2025-03-02 23:06:12 +01:00
parent c322d42ffe
commit 6dab472b9d

View file

@ -11,8 +11,31 @@ impl Rectangle {
height: size,
}
}
fn can_hold(&self, other: &Rectangle) -> bool {
self.width > other.width && self.height > other.height
}
}
fn main() {
let sq = Rectangle::square(3);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn larger_can_hold_smaller() {
let larger = Rectangle {
width: 8,
height: 7,
};
let smaller = Rectangle {
width: 5,
height: 1,
};
assert!(larger.can_hold(&smaller));
}
}