Skip to content

Commit dc1f3b7

Browse files
author
liv
committed
add tests; refactor exercise links
1 parent 141db77 commit dc1f3b7

File tree

11 files changed

+51
-26
lines changed

11 files changed

+51
-26
lines changed

exercises/if/if1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub fn bigger(a: i32, b:i32) -> i32 {
99
// Scroll down for hints.
1010
}
1111

12+
// Don't mind this for now :)
1213
#[cfg(test)]
1314
mod tests {
1415
use super::*;

exercises/primitive_types/primitive_types4.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ fn main() {
3939

4040

4141
// Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book:
42-
// https://doc.rust-lang.org/stable/book/second-edition/ch04-03-slices.html#other-slices
42+
// https://doc.rust-lang.org/book/ch04-03-slices.html
4343
// and use the starting and ending indices of the items in the Array
4444
// that you want to end up in the slice.
4545

4646
// If you're curious why the right hand of the `==` comparison does not
4747
// have an ampersand for a reference since the left hand side is a
4848
// reference, take a look at the Deref coercions section of the book:
49-
// https://doc.rust-lang.org/stable/book/second-edition/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods
49+
// https://doc.rust-lang.org/book/ch15-02-deref.html

exercises/primitive_types/primitive_types5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn main() {
3939

4040

4141
// Take a look at the Data Types -> The Tuple Type section of the book:
42-
// https://doc.rust-lang.org/stable/book/second-edition/ch03-02-data-types.html#the-tuple-type
42+
// https://doc.rust-lang.org/stable/book/ch03-02-data-types.html#the-tuple-type
4343
// Particularly the part about destructuring (second to last example in the section).
4444
// You'll need to make a pattern to bind `name` and `age` to the appropriate parts
4545
// of the tuple. You can do it!!

exercises/primitive_types/primitive_types6.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ fn main() {
4141
// While you could use a destructuring `let` for the tuple here, try
4242
// indexing into it instead, as explained in the last example of the
4343
// Data Types -> The Tuple Type section of the book:
44-
// https://doc.rust-lang.org/stable/book/second-edition/ch03-02-data-types.html#the-tuple-type
44+
// https://doc.rust-lang.org/stable/book/ch03-02-data-types.html#the-tuple-type
4545
// Now you have another tool in your toolbox!

exercises/test1.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
// test1.rs
2-
// Make me compile! Scroll down for hints :)
2+
// This is a test for the following sections:
3+
// - Variables
4+
// - Functions
35

4-
fn something() -> [f32; 120] {
5-
???
6-
}
7-
8-
fn something_else() -> String {
9-
???
10-
}
6+
// Mary is buying apples. One apple usually costs 2 dollars, but if you buy
7+
// more than 40 at once, each apple only costs 1! Write a function that calculates
8+
// the price of an order of apples given the order amount.
119

1210
fn main() {
13-
println!("This array is {} items long, and it should be 120", something().len());
14-
println!("This function returns a string: {}", something_else());
11+
let price1 = calculateprice(55);
12+
let price2 = calculateprice(40);
13+
14+
// Don't modify this!
15+
if price1 == 55 && price2 == 80 {
16+
println!("Good job!");
17+
} else {
18+
panic!("Uh oh! Wrong price!");
19+
}
1520
}

exercises/tests/tests4.rs renamed to exercises/test2.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// tests4.rs
1+
// test2.rs
2+
// This is a test for the following sections:
3+
// - Tests
4+
25
// This test isn't testing our function -- make it do that in such a way that
36
// the test passes. Then write a second test that tests that we get the result
47
// we expect to get when we call `times_two` with a negative number.

exercises/strings/strings3.rs renamed to exercises/test3.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// strings3.rs
2+
// This is a test for the following sections:
3+
// - Strings
4+
25
// Ok, here are a bunch of values-- some are `Strings`, some are `&strs`. Your
36
// task is to call one of these two functions on each value depending on what
47
// you think each value is. That is, add either `string_slice` or `string`

exercises/test4.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// test4.rs
2+
// This test covers the sections:
3+
// - Modules
4+
// - Macros
5+
6+
// Write a macro that passes the test! No hints this time, you can do it!
7+
8+
fn main() {
9+
if my_macro!("world!") != "Hello world!" {
10+
panic!("Oh no! Wrong output!");
11+
}
12+
}

exercises/tests/tests1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// tests1.rs
22
// Tests are important to ensure that your code does what you think it should do.
33
// Tests can be run on this file with the following command:
4-
// rustc --test tests1.rs
4+
// rustlings run --test exercises/tests/tests1.rs
55

66
// This test has a problem with it -- make the test compile! Make the test
77
// pass! Make the test fail! Scroll down for hints :)

exercises/tests/tests3.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// tests3.rs
22
// This test isn't testing our function -- make it do that in such a way that
3-
// the test passes. Then write a second test that tests that we get the result
3+
// the test passes. Then write a second test that tests whether we get the result
44
// we expect to get when we call `is_even(5)`. Scroll down for hints!
55

66
pub fn is_even(num: i32) -> bool {
@@ -13,7 +13,7 @@ mod tests {
1313

1414
#[test]
1515
fn is_true_when_even() {
16-
assert!(false);
16+
assert!();
1717
}
1818
}
1919

0 commit comments

Comments
 (0)