Add tests for the rectangles
project
This commit is contained in:
parent
c322d42ffe
commit
6dab472b9d
1 changed files with 23 additions and 0 deletions
|
@ -11,8 +11,31 @@ impl Rectangle {
|
||||||
height: size,
|
height: size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn can_hold(&self, other: &Rectangle) -> bool {
|
||||||
|
self.width > other.width && self.height > other.height
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let sq = Rectangle::square(3);
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue