Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrx123 committed Apr 15, 2024
1 parent 6dfab6b commit 3df1b1d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
4 changes: 1 addition & 3 deletions exercises/17_tests/tests1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
// 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/17_tests/tests2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
// 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!(true, true);
}
}
7 changes: 3 additions & 4 deletions exercises/17_tests/tests3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// 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 @@ -19,11 +17,12 @@ mod tests {

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

#[test]
fn is_false_when_odd() {
assert!();
let result = is_even(5);
assert!(!result);
}
}
18 changes: 9 additions & 9 deletions exercises/17_tests/tests4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
// 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 {
// Only change the test functions themselves
pub fn new(width: i32, height: i32) -> Self {
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 }
}
}

Expand All @@ -30,19 +28,21 @@ 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(expected = "Rectangle width and height cannot be negative!")]
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);
Rectangle::new(-10, 10);
}

#[test]
#[should_panic(expected = "Rectangle width and height cannot be negative!")]
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);
Rectangle::new(10, -10);
}
}

0 comments on commit 3df1b1d

Please sign in to comment.