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/README.md7
-rw-r--r--rustlings/exercises/17_tests/tests1.rs24
-rw-r--r--rustlings/exercises/17_tests/tests2.rs23
-rw-r--r--rustlings/exercises/17_tests/tests3.rs51
4 files changed, 0 insertions, 105 deletions
diff --git a/rustlings/exercises/17_tests/README.md b/rustlings/exercises/17_tests/README.md
deleted file mode 100644
index 27c6818..0000000
--- a/rustlings/exercises/17_tests/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
-# Tests
-
-Going out of order from the book to cover tests -- many of the following exercises will ask you to make tests pass!
-
-## Further information
-
-- [Writing Tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html)
diff --git a/rustlings/exercises/17_tests/tests1.rs b/rustlings/exercises/17_tests/tests1.rs
deleted file mode 100644
index 7fd7e10..0000000
--- a/rustlings/exercises/17_tests/tests1.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-// Tests are important to ensure that your code does what you think it should
-// do.
-
-fn is_even(n: i64) -> bool {
- n % 2 == 0
-}
-
-fn main() {
- // You can optionally experiment here.
-}
-
-#[cfg(test)]
-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!(is_even(2));
- assert!(!is_even(3));
- }
-}
diff --git a/rustlings/exercises/17_tests/tests2.rs b/rustlings/exercises/17_tests/tests2.rs
deleted file mode 100644
index 16bf0fa..0000000
--- a/rustlings/exercises/17_tests/tests2.rs
+++ /dev/null
@@ -1,23 +0,0 @@
-// Calculates the power of 2 using a bit shift.
-// `1 << n` is equivalent to "2 to the power of n".
-fn power_of_2(n: u8) -> u64 {
- 1 << n
-}
-
-fn main() {
- // You can optionally experiment here.
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn you_can_assert_eq() {
- // TODO: Test the function `power_of_2` with some values.
- 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
deleted file mode 100644
index 085bb62..0000000
--- a/rustlings/exercises/17_tests/tests3.rs
+++ /dev/null
@@ -1,51 +0,0 @@
-struct Rectangle {
- width: i32,
- height: i32,
-}
-
-impl Rectangle {
- // Don't change this function.
- fn new(width: i32, height: i32) -> Self {
- if width <= 0 || height <= 0 {
- // Returning a `Result` would be better here. But we want to learn
- // how to test functions that can panic.
- panic!("Rectangle width and height must be positive");
- }
-
- Rectangle { width, height }
- }
-}
-
-fn main() {
- // You can optionally experiment here.
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn correct_width_and_height() {
- // 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!(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);
- }
-
- // 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);
- }
-}