Skip to content

Commit

Permalink
Merge pull request #18 from Joaopmorais/test
Browse files Browse the repository at this point in the history
tests exercises
  • Loading branch information
Joaopmorais committed Feb 20, 2024
2 parents 2d32ebe + 20f2f10 commit 9149644
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
3 changes: 1 addition & 2 deletions exercises/17_tests/tests1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
// 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);
}
}
6 changes: 3 additions & 3 deletions exercises/17_tests/tests2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
// 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!();
let a =3;
let b=3;
assert_eq!(a,b);
}
}
9 changes: 6 additions & 3 deletions exercises/17_tests/tests3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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 +18,15 @@ mod tests {

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

#[test]
fn is_false_when_odd() {
assert!();
assert!(!is_even(3));
}

fn is_true_or_false(){
assert!(is_even(5))
}
}
9 changes: 6 additions & 3 deletions exercises/17_tests/tests4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Execute `rustlings hint tests4` or use the `hint` watch subcommand for a
// hint.

// I AM NOT DONE

struct Rectangle {
width: i32,
Expand All @@ -30,19 +29,23 @@ 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);

}
}

0 comments on commit 9149644

Please sign in to comment.