summaryrefslogtreecommitdiff
path: root/rustlings/exercises/17_tests
diff options
context:
space:
mode:
Diffstat (limited to 'rustlings/exercises/17_tests')
-rw-r--r--rustlings/exercises/17_tests/tests1.rs5
-rw-r--r--rustlings/exercises/17_tests/tests2.rs8
-rw-r--r--rustlings/exercises/17_tests/tests3.rs6
3 files changed, 11 insertions, 8 deletions
diff --git a/rustlings/exercises/17_tests/tests1.rs b/rustlings/exercises/17_tests/tests1.rs
index 7529f9f..7fd7e10 100644
--- a/rustlings/exercises/17_tests/tests1.rs
+++ b/rustlings/exercises/17_tests/tests1.rs
@@ -13,11 +13,12 @@ fn main() {
mod tests {
// TODO: Import `is_even`. You can use a wildcard to import everything in
// the outer module.
+ use super::*;
#[test]
fn you_can_assert() {
// TODO: Test the function `is_even` with some values.
- assert!();
- assert!();
+ assert!(is_even(2));
+ assert!(!is_even(3));
}
}
diff --git a/rustlings/exercises/17_tests/tests2.rs b/rustlings/exercises/17_tests/tests2.rs
index 0c6573e..16bf0fa 100644
--- a/rustlings/exercises/17_tests/tests2.rs
+++ b/rustlings/exercises/17_tests/tests2.rs
@@ -15,9 +15,9 @@ mod tests {
#[test]
fn you_can_assert_eq() {
// TODO: Test the function `power_of_2` with some values.
- assert_eq!();
- assert_eq!();
- assert_eq!();
- assert_eq!();
+ assert_eq!(power_of_2(1), 2);
+ assert_eq!(power_of_2(2), 4);
+ assert_eq!(power_of_2(3), 8);
+ assert_eq!(power_of_2(4), 16);
}
}
diff --git a/rustlings/exercises/17_tests/tests3.rs b/rustlings/exercises/17_tests/tests3.rs
index 822184e..085bb62 100644
--- a/rustlings/exercises/17_tests/tests3.rs
+++ b/rustlings/exercises/17_tests/tests3.rs
@@ -29,13 +29,14 @@ mod tests {
// TODO: This test should check if the rectangle has the size that we
// pass to its constructor.
let rect = Rectangle::new(10, 20);
- assert_eq!(todo!(), 10); // Check width
- assert_eq!(todo!(), 20); // Check height
+ assert_eq!(rect.width, 10); // Check width
+ assert_eq!(rect.height, 20); // Check height
}
// TODO: This test should check if the program panics when we try to create
// a rectangle with negative width.
#[test]
+ #[should_panic]
fn negative_width() {
let _rect = Rectangle::new(-10, 10);
}
@@ -43,6 +44,7 @@ mod tests {
// TODO: This test should check if the program panics when we try to create
// a rectangle with negative height.
#[test]
+ #[should_panic]
fn negative_height() {
let _rect = Rectangle::new(10, -10);
}