Skip to content

Commit

Permalink
tests4: panic test
Browse files Browse the repository at this point in the history
  • Loading branch information
vhuynhle committed Aug 27, 2023
1 parent 59c9ca2 commit 1ff0a5f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions exercises/tests/tests4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
// Execute `rustlings hint tests4` or use the `hint` watch subcommand for a
// hint.

// I AM NOT DONE

struct Rectangle {
width: i32,
height: i32
height: i32,
}

impl Rectangle {
Expand All @@ -18,7 +17,7 @@ impl Rectangle {
if width <= 0 || height <= 0 {
panic!("Rectangle width and height cannot be negative!")
}
Rectangle {width, height}
Rectangle { width, height }
}
}

Expand All @@ -30,17 +29,19 @@ mod tests {
fn correct_width_and_height() {
// This test should check if the rectangle is the size that we pass into its constructor
let rect = Rectangle::new(10, 20);
assert_eq!(???, 10); // check width
assert_eq!(???, 20); // check height
assert_eq!(rect.width, 10); // check width
assert_eq!(rect.height, 20); // check height
}

#[test]
#[should_panic]
fn negative_width() {
// This test should check if program panics when we try to create rectangle with negative width
let _rect = Rectangle::new(-10, 10);
}

#[test]
#[should_panic]
fn negative_height() {
// This test should check if program panics when we try to create rectangle with negative height
let _rect = Rectangle::new(10, -10);
Expand Down

0 comments on commit 1ff0a5f

Please sign in to comment.