feat: completed tests

This commit is contained in:
2026-09-13 01:13:24 +02:00
parent c7f0365fec
commit 5c1324aae8
3 changed files with 11 additions and 8 deletions
+3 -2
View File
@@ -13,11 +13,12 @@ fn main() {
mod tests { mod tests {
// TODO: Import `is_even`. You can use a wildcard to import everything in // TODO: Import `is_even`. You can use a wildcard to import everything in
// the outer module. // the outer module.
use super::*;
#[test] #[test]
fn you_can_assert() { fn you_can_assert() {
// TODO: Test the function `is_even` with some values. // TODO: Test the function `is_even` with some values.
assert!(); assert!(!is_even(1));
assert!(); assert!(is_even(12));
} }
} }
+4 -4
View File
@@ -15,9 +15,9 @@ mod tests {
#[test] #[test]
fn you_can_assert_eq() { fn you_can_assert_eq() {
// TODO: Test the function `power_of_2` with some values. // TODO: Test the function `power_of_2` with some values.
assert_eq!(); assert_eq!(power_of_2(2), 4);
assert_eq!(); assert_eq!(power_of_2(3), 8);
assert_eq!(); assert_eq!(power_of_2(10), 1024);
assert_eq!(); assert_eq!(power_of_2(42), 4398046511104);
} }
} }
+4 -2
View File
@@ -29,13 +29,14 @@ mod tests {
// TODO: This test should check if the rectangle has the size that we // TODO: This test should check if the rectangle has the size that we
// pass to its constructor. // pass to its constructor.
let rect = Rectangle::new(10, 20); let rect = Rectangle::new(10, 20);
assert_eq!(todo!(), 10); // Check width assert_eq!(rect.width, 10); // Check width
assert_eq!(todo!(), 20); // Check height assert_eq!(rect.height, 20); // Check height
} }
// TODO: This test should check if the program panics when we try to create // TODO: This test should check if the program panics when we try to create
// a rectangle with negative width. // a rectangle with negative width.
#[test] #[test]
#[should_panic]
fn negative_width() { fn negative_width() {
let _rect = Rectangle::new(-10, 10); 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 // TODO: This test should check if the program panics when we try to create
// a rectangle with negative height. // a rectangle with negative height.
#[test] #[test]
#[should_panic]
fn negative_height() { fn negative_height() {
let _rect = Rectangle::new(10, -10); let _rect = Rectangle::new(10, -10);
} }