summaryrefslogtreecommitdiff
path: root/old_curriculum/tests
diff options
context:
space:
mode:
authorolivia <olivia@fastmail.com>2018-04-26 21:29:11 +0200
committerolivia <olivia@fastmail.com>2018-04-26 21:29:11 +0200
commit5e89d1e888a8fafc39096afce36d02e313f349c2 (patch)
tree97b13f8223012d1db88d510cd79ea0e49570d1f7 /old_curriculum/tests
parent32ac403da5c49b002ba420186d3122501196ff89 (diff)
move old files to a separate directory
Diffstat (limited to 'old_curriculum/tests')
-rw-r--r--old_curriculum/tests/tests1.rs49
-rw-r--r--old_curriculum/tests/tests2.rs44
-rw-r--r--old_curriculum/tests/tests3.rs43
-rw-r--r--old_curriculum/tests/tests4.rs19
4 files changed, 155 insertions, 0 deletions
diff --git a/old_curriculum/tests/tests1.rs b/old_curriculum/tests/tests1.rs
new file mode 100644
index 0000000..959ed85
--- /dev/null
+++ b/old_curriculum/tests/tests1.rs
@@ -0,0 +1,49 @@
+// tests1.rs
+// Tests are important to ensure that your code does what you think it should do.
+// Tests can be run on this file with the following command:
+// rustc --test tests1.rs
+
+// This test has a problem with it -- make the test compile! Make the test
+// pass! Make the test fail! Scroll down for hints :)
+
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn you_can_assert() {
+ assert!();
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// You don't even need to write any code to test -- you can just test values and run that, even
+// though you wouldn't do that in real life :) `assert!` is a macro that needs an argument.
+// Depending on the value of the argument, `assert!` will do nothing (in which case the test will
+// pass) or `assert!` will panic (in which case the test will fail). So try giving different values
+// to `assert!` and see which ones compile, which ones pass, and which ones fail :)
diff --git a/old_curriculum/tests/tests2.rs b/old_curriculum/tests/tests2.rs
new file mode 100644
index 0000000..6775d61
--- /dev/null
+++ b/old_curriculum/tests/tests2.rs
@@ -0,0 +1,44 @@
+// tests2.rs
+// This test has a problem with it -- make the test compile! Make the test
+// pass! Make the test fail! Scroll down for hints :)
+
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn you_can_assert_eq() {
+ assert_eq!();
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// Like the previous exercise, you don't need to write any code to get this test to compile and
+// run. `assert_eq!` is a macro that takes two arguments and compares them. Try giving it two
+// values that are equal! Try giving it two arguments that are different! Try giving it two values
+// that are of different types! Try switching which argument comes first and which comes second!
diff --git a/old_curriculum/tests/tests3.rs b/old_curriculum/tests/tests3.rs
new file mode 100644
index 0000000..e041f38
--- /dev/null
+++ b/old_curriculum/tests/tests3.rs
@@ -0,0 +1,43 @@
+// tests3.rs
+// This test isn't testing our function -- make it do that in such a way that
+// the test passes. Then write a second test that tests that we get the result
+// we expect to get when we call `is_even(5)`. Scroll down for hints!
+
+pub fn is_even(num: i32) -> bool {
+ num % 2 == 0
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn is_true_when_even() {
+ assert!(false);
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// You can call a function right where you're passing arguments to `assert!` -- so you could do
+// something like `assert!(having_fun())`. If you want to check that you indeed get false, you
+// can negate the result of what you're doing using `!`, like `assert!(!having_fun())`.
diff --git a/old_curriculum/tests/tests4.rs b/old_curriculum/tests/tests4.rs
new file mode 100644
index 0000000..23d444a
--- /dev/null
+++ b/old_curriculum/tests/tests4.rs
@@ -0,0 +1,19 @@
+// tests4.rs
+// This test isn't testing our function -- make it do that in such a way that
+// the test passes. Then write a second test that tests that we get the result
+// we expect to get when we call `times_two` with a negative number.
+// No hints, you can do this :)
+
+pub fn times_two(num: i32) -> i32 {
+ num * 2
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn returns_twice_of_positive_numbers() {
+ assert_eq!(4, 4);
+ }
+}