File tree Expand file tree Collapse file tree 11 files changed +51
-26
lines changed Expand file tree Collapse file tree 11 files changed +51
-26
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ pub fn bigger(a: i32, b:i32) -> i32 {
9
9
// Scroll down for hints.
10
10
}
11
11
12
+ // Don't mind this for now :)
12
13
#[ cfg( test) ]
13
14
mod tests {
14
15
use super :: * ;
Original file line number Diff line number Diff line change @@ -39,11 +39,11 @@ fn main() {
39
39
40
40
41
41
// 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
43
43
// and use the starting and ending indices of the items in the Array
44
44
// that you want to end up in the slice.
45
45
46
46
// If you're curious why the right hand of the `==` comparison does not
47
47
// have an ampersand for a reference since the left hand side is a
48
48
// 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
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ fn main() {
39
39
40
40
41
41
// 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
43
43
// Particularly the part about destructuring (second to last example in the section).
44
44
// You'll need to make a pattern to bind `name` and `age` to the appropriate parts
45
45
// of the tuple. You can do it!!
Original file line number Diff line number Diff line change @@ -41,5 +41,5 @@ fn main() {
41
41
// While you could use a destructuring `let` for the tuple here, try
42
42
// indexing into it instead, as explained in the last example of the
43
43
// 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
45
45
// Now you have another tool in your toolbox!
Original file line number Diff line number Diff line change 1
1
// test1.rs
2
- // Make me compile! Scroll down for hints :)
2
+ // This is a test for the following sections:
3
+ // - Variables
4
+ // - Functions
3
5
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.
11
9
12
10
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
+ }
15
20
}
Original file line number Diff line number Diff line change 1
- // tests4.rs
1
+ // test2.rs
2
+ // This is a test for the following sections:
3
+ // - Tests
4
+
2
5
// This test isn't testing our function -- make it do that in such a way that
3
6
// the test passes. Then write a second test that tests that we get the result
4
7
// we expect to get when we call `times_two` with a negative number.
Original file line number Diff line number Diff line change 1
1
// strings3.rs
2
+ // This is a test for the following sections:
3
+ // - Strings
4
+
2
5
// Ok, here are a bunch of values-- some are `Strings`, some are `&strs`. Your
3
6
// task is to call one of these two functions on each value depending on what
4
7
// you think each value is. That is, add either `string_slice` or `string`
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
// tests1.rs
2
2
// Tests are important to ensure that your code does what you think it should do.
3
3
// Tests can be run on this file with the following command:
4
- // rustc --test tests1.rs
4
+ // rustlings run --test exercises/tests/ tests1.rs
5
5
6
6
// This test has a problem with it -- make the test compile! Make the test
7
7
// pass! Make the test fail! Scroll down for hints :)
Original file line number Diff line number Diff line change 1
1
// tests3.rs
2
2
// 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
4
4
// we expect to get when we call `is_even(5)`. Scroll down for hints!
5
5
6
6
pub fn is_even ( num : i32 ) -> bool {
@@ -13,7 +13,7 @@ mod tests {
13
13
14
14
#[ test]
15
15
fn is_true_when_even ( ) {
16
- assert ! ( false ) ;
16
+ assert ! ( ) ;
17
17
}
18
18
}
19
19
You can’t perform that action at this time.
0 commit comments