Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
afresquet committed Apr 19, 2023
1 parent 698ed51 commit 10d0e1b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
4 changes: 1 addition & 3 deletions exercises/tests/tests1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
// pass! Make the test fail!
// Execute `rustlings hint tests1` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE

#[cfg(test)]
mod tests {
#[test]
fn you_can_assert() {
assert!();
assert!(true);
}
}
4 changes: 1 addition & 3 deletions exercises/tests/tests2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
// pass! Make the test fail!
// Execute `rustlings hint tests2` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE

#[cfg(test)]
mod tests {
#[test]
fn you_can_assert_eq() {
assert_eq!();
assert_eq!(1, 1);
}
}
6 changes: 2 additions & 4 deletions exercises/tests/tests3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// we expect to get when we call `is_even(5)`.
// Execute `rustlings hint tests3` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE

pub fn is_even(num: i32) -> bool {
num % 2 == 0
}
Expand All @@ -16,11 +14,11 @@ mod tests {

#[test]
fn is_true_when_even() {
assert!();
assert!(is_even(2));
}

#[test]
fn is_false_when_odd() {
assert!();
assert!(!is_even(1));
}
}
12 changes: 6 additions & 6 deletions exercises/tests/tests4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// Make sure that we're testing for the correct conditions!
// 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 @@ -15,7 +13,7 @@ impl Rectangle {
if width <= 0 || height <= 0 {
panic!("Rectangle width and height cannot be negative!")
}
Rectangle {width, height}
Rectangle { width, height }
}
}

Expand All @@ -27,17 +25,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 10d0e1b

Please sign in to comment.