mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-01-13 00:00:03 +03:00
Complete tests exercises
This commit is contained in:
parent
92c8633178
commit
34e542a471
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,11 @@
|
|||
// 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 new_string = "test";
|
||||
assert_eq!(new_string, "test");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn is_true_when_even() {
|
||||
assert!();
|
||||
assert!(is_even(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_false_when_odd() {
|
||||
assert!();
|
||||
assert!(!is_even(5));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
// Execute `rustlings hint tests4` or use the `hint` watch subcommand for a
|
||||
// hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
struct Rectangle {
|
||||
width: i32,
|
||||
height: i32
|
||||
|
@ -30,17 +28,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);
|
||||
|
|
Loading…
Reference in a new issue