changed comments in tests
also fixed small logical issue in `Rectangle::new()` where u could create rectangle with width or height equals 0
This commit is contained in:
parent
c4974ac782
commit
102d7f3d0e
@ -12,7 +12,7 @@ struct Rectangle {
|
|||||||
impl Rectangle {
|
impl Rectangle {
|
||||||
// Only change the test functions themselves
|
// Only change the test functions themselves
|
||||||
pub fn new(width: i32, height: i32) -> Self {
|
pub fn new(width: i32, height: i32) -> Self {
|
||||||
if width < 0 || height < 0 {
|
if width <= 0 || height <= 0 {
|
||||||
panic!("Rectangle width and height cannot be negative!")
|
panic!("Rectangle width and height cannot be negative!")
|
||||||
}
|
}
|
||||||
Rectangle {width, height}
|
Rectangle {width, height}
|
||||||
@ -33,13 +33,13 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn negative_width() {
|
fn negative_width() {
|
||||||
// This test should check if thread panics when we try to create rectangle with negative width
|
// This test should check if program panics when we try to create rectangle with negative width
|
||||||
let _rect = Rectangle::new(-10, 10);
|
let _rect = Rectangle::new(-10, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn negative_height() {
|
fn negative_height() {
|
||||||
// This test should check if thread panics when we try to create rectangle with negative height
|
// This test should check if program panics when we try to create rectangle with negative height
|
||||||
let _rect = Rectangle::new(10, -10);
|
let _rect = Rectangle::new(10, -10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user