add tests; refactor exercise links
This commit is contained in:
parent
141db7795b
commit
dc1f3b79f8
@ -9,6 +9,7 @@ pub fn bigger(a: i32, b:i32) -> i32 {
|
|||||||
// Scroll down for hints.
|
// Scroll down for hints.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't mind this for now :)
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -39,11 +39,11 @@ fn main() {
|
|||||||
|
|
||||||
|
|
||||||
// Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book:
|
// Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book:
|
||||||
// https://doc.rust-lang.org/stable/book/second-edition/ch04-03-slices.html#other-slices
|
// https://doc.rust-lang.org/book/ch04-03-slices.html
|
||||||
// and use the starting and ending indices of the items in the Array
|
// and use the starting and ending indices of the items in the Array
|
||||||
// that you want to end up in the slice.
|
// that you want to end up in the slice.
|
||||||
|
|
||||||
// If you're curious why the right hand of the `==` comparison does not
|
// If you're curious why the right hand of the `==` comparison does not
|
||||||
// have an ampersand for a reference since the left hand side is a
|
// have an ampersand for a reference since the left hand side is a
|
||||||
// reference, take a look at the Deref coercions section of the book:
|
// reference, take a look at the Deref coercions section of the book:
|
||||||
// https://doc.rust-lang.org/stable/book/second-edition/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods
|
// https://doc.rust-lang.org/book/ch15-02-deref.html
|
||||||
|
@ -39,7 +39,7 @@ fn main() {
|
|||||||
|
|
||||||
|
|
||||||
// Take a look at the Data Types -> The Tuple Type section of the book:
|
// Take a look at the Data Types -> The Tuple Type section of the book:
|
||||||
// https://doc.rust-lang.org/stable/book/second-edition/ch03-02-data-types.html#the-tuple-type
|
// https://doc.rust-lang.org/stable/book/ch03-02-data-types.html#the-tuple-type
|
||||||
// Particularly the part about destructuring (second to last example in the section).
|
// Particularly the part about destructuring (second to last example in the section).
|
||||||
// You'll need to make a pattern to bind `name` and `age` to the appropriate parts
|
// You'll need to make a pattern to bind `name` and `age` to the appropriate parts
|
||||||
// of the tuple. You can do it!!
|
// of the tuple. You can do it!!
|
||||||
|
@ -41,5 +41,5 @@ fn main() {
|
|||||||
// While you could use a destructuring `let` for the tuple here, try
|
// While you could use a destructuring `let` for the tuple here, try
|
||||||
// indexing into it instead, as explained in the last example of the
|
// indexing into it instead, as explained in the last example of the
|
||||||
// Data Types -> The Tuple Type section of the book:
|
// Data Types -> The Tuple Type section of the book:
|
||||||
// https://doc.rust-lang.org/stable/book/second-edition/ch03-02-data-types.html#the-tuple-type
|
// https://doc.rust-lang.org/stable/book/ch03-02-data-types.html#the-tuple-type
|
||||||
// Now you have another tool in your toolbox!
|
// Now you have another tool in your toolbox!
|
||||||
|
@ -1,15 +1,20 @@
|
|||||||
// test1.rs
|
// test1.rs
|
||||||
// Make me compile! Scroll down for hints :)
|
// This is a test for the following sections:
|
||||||
|
// - Variables
|
||||||
|
// - Functions
|
||||||
|
|
||||||
fn something() -> [f32; 120] {
|
// Mary is buying apples. One apple usually costs 2 dollars, but if you buy
|
||||||
???
|
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
||||||
}
|
// the price of an order of apples given the order amount.
|
||||||
|
|
||||||
fn something_else() -> String {
|
|
||||||
???
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("This array is {} items long, and it should be 120", something().len());
|
let price1 = calculateprice(55);
|
||||||
println!("This function returns a string: {}", something_else());
|
let price2 = calculateprice(40);
|
||||||
|
|
||||||
|
// Don't modify this!
|
||||||
|
if price1 == 55 && price2 == 80 {
|
||||||
|
println!("Good job!");
|
||||||
|
} else {
|
||||||
|
panic!("Uh oh! Wrong price!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
// tests4.rs
|
// test2.rs
|
||||||
|
// This is a test for the following sections:
|
||||||
|
// - Tests
|
||||||
|
|
||||||
// This test isn't testing our function -- make it do that in such a way that
|
// 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
|
// 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.
|
// we expect to get when we call `times_two` with a negative number.
|
@ -1,4 +1,7 @@
|
|||||||
// strings3.rs
|
// strings3.rs
|
||||||
|
// This is a test for the following sections:
|
||||||
|
// - Strings
|
||||||
|
|
||||||
// Ok, here are a bunch of values-- some are `Strings`, some are `&strs`. Your
|
// Ok, here are a bunch of values-- some are `Strings`, some are `&strs`. Your
|
||||||
// task is to call one of these two functions on each value depending on what
|
// task is to call one of these two functions on each value depending on what
|
||||||
// you think each value is. That is, add either `string_slice` or `string`
|
// you think each value is. That is, add either `string_slice` or `string`
|
12
exercises/test4.rs
Normal file
12
exercises/test4.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// test4.rs
|
||||||
|
// This test covers the sections:
|
||||||
|
// - Modules
|
||||||
|
// - Macros
|
||||||
|
|
||||||
|
// Write a macro that passes the test! No hints this time, you can do it!
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if my_macro!("world!") != "Hello world!" {
|
||||||
|
panic!("Oh no! Wrong output!");
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
// tests1.rs
|
// tests1.rs
|
||||||
// Tests are important to ensure that your code does what you think it should do.
|
// 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:
|
// Tests can be run on this file with the following command:
|
||||||
// rustc --test tests1.rs
|
// rustlings run --test exercises/tests/tests1.rs
|
||||||
|
|
||||||
// This test has a problem with it -- make the test compile! Make the test
|
// This test has a problem with it -- make the test compile! Make the test
|
||||||
// pass! Make the test fail! Scroll down for hints :)
|
// pass! Make the test fail! Scroll down for hints :)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// tests3.rs
|
// tests3.rs
|
||||||
// This test isn't testing our function -- make it do that in such a way that
|
// 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
|
// the test passes. Then write a second test that tests whether we get the result
|
||||||
// we expect to get when we call `is_even(5)`. Scroll down for hints!
|
// we expect to get when we call `is_even(5)`. Scroll down for hints!
|
||||||
|
|
||||||
pub fn is_even(num: i32) -> bool {
|
pub fn is_even(num: i32) -> bool {
|
||||||
@ -13,7 +13,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_true_when_even() {
|
fn is_true_when_even() {
|
||||||
assert!(false);
|
assert!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,36 +8,37 @@ pub fn verify() -> Result<(), ()> {
|
|||||||
compile_only("exercises/variables/variables2.rs")?;
|
compile_only("exercises/variables/variables2.rs")?;
|
||||||
compile_only("exercises/variables/variables3.rs")?;
|
compile_only("exercises/variables/variables3.rs")?;
|
||||||
compile_only("exercises/variables/variables4.rs")?;
|
compile_only("exercises/variables/variables4.rs")?;
|
||||||
|
test("exercises/if/if1.rs")?;
|
||||||
compile_only("exercises/functions/functions1.rs")?;
|
compile_only("exercises/functions/functions1.rs")?;
|
||||||
compile_only("exercises/functions/functions2.rs")?;
|
compile_only("exercises/functions/functions2.rs")?;
|
||||||
compile_only("exercises/functions/functions3.rs")?;
|
compile_only("exercises/functions/functions3.rs")?;
|
||||||
compile_only("exercises/functions/functions4.rs")?;
|
compile_only("exercises/functions/functions4.rs")?;
|
||||||
compile_only("exercises/functions/functions5.rs")?;
|
compile_only("exercises/functions/functions5.rs")?;
|
||||||
|
compile_only("exercises/test1.rs")?;
|
||||||
compile_only("exercises/primitive_types/primitive_types1.rs")?;
|
compile_only("exercises/primitive_types/primitive_types1.rs")?;
|
||||||
compile_only("exercises/primitive_types/primitive_types2.rs")?;
|
compile_only("exercises/primitive_types/primitive_types2.rs")?;
|
||||||
compile_only("exercises/primitive_types/primitive_types3.rs")?;
|
compile_only("exercises/primitive_types/primitive_types3.rs")?;
|
||||||
compile_only("exercises/primitive_types/primitive_types4.rs")?;
|
compile_only("exercises/primitive_types/primitive_types4.rs")?;
|
||||||
compile_only("exercises/primitive_types/primitive_types5.rs")?;
|
compile_only("exercises/primitive_types/primitive_types5.rs")?;
|
||||||
compile_only("exercises/primitive_types/primitive_types6.rs")?;
|
compile_only("exercises/primitive_types/primitive_types6.rs")?;
|
||||||
compile_only("exercises/test1.rs")?;
|
|
||||||
test("exercises/tests/tests1.rs")?;
|
test("exercises/tests/tests1.rs")?;
|
||||||
test("exercises/tests/tests2.rs")?;
|
test("exercises/tests/tests2.rs")?;
|
||||||
test("exercises/tests/tests3.rs")?;
|
test("exercises/tests/tests3.rs")?;
|
||||||
test("exercises/tests/tests4.rs")?;
|
test("exercises/test2.rs")?;
|
||||||
test("exercises/if/if1.rs")?;
|
|
||||||
compile_only("exercises/strings/strings1.rs")?;
|
compile_only("exercises/strings/strings1.rs")?;
|
||||||
compile_only("exercises/strings/strings2.rs")?;
|
compile_only("exercises/strings/strings2.rs")?;
|
||||||
compile_only("exercises/strings/strings3.rs")?;
|
compile_only("exercises/test3.rs")?;
|
||||||
compile_only("exercises/move_semantics/move_semantics1.rs")?;
|
|
||||||
compile_only("exercises/move_semantics/move_semantics2.rs")?;
|
|
||||||
compile_only("exercises/move_semantics/move_semantics3.rs")?;
|
|
||||||
compile_only("exercises/move_semantics/move_semantics4.rs")?;
|
|
||||||
compile_only("exercises/modules/modules1.rs")?;
|
compile_only("exercises/modules/modules1.rs")?;
|
||||||
compile_only("exercises/modules/modules2.rs")?;
|
compile_only("exercises/modules/modules2.rs")?;
|
||||||
compile_only("exercises/macros/macros1.rs")?;
|
compile_only("exercises/macros/macros1.rs")?;
|
||||||
compile_only("exercises/macros/macros2.rs")?;
|
compile_only("exercises/macros/macros2.rs")?;
|
||||||
compile_only("exercises/macros/macros3.rs")?;
|
compile_only("exercises/macros/macros3.rs")?;
|
||||||
compile_only("exercises/macros/macros4.rs")?;
|
compile_only("exercises/macros/macros4.rs")?;
|
||||||
|
compile_only("exercises/test4.rs")?;
|
||||||
|
compile_only("exercises/move_semantics/move_semantics1.rs")?;
|
||||||
|
compile_only("exercises/move_semantics/move_semantics2.rs")?;
|
||||||
|
compile_only("exercises/move_semantics/move_semantics3.rs")?;
|
||||||
|
compile_only("exercises/move_semantics/move_semantics4.rs")?;
|
||||||
test("exercises/error_handling/errors1.rs")?;
|
test("exercises/error_handling/errors1.rs")?;
|
||||||
test("exercises/error_handling/errors2.rs")?;
|
test("exercises/error_handling/errors2.rs")?;
|
||||||
test("exercises/error_handling/errors3.rs")?;
|
test("exercises/error_handling/errors3.rs")?;
|
||||||
|
Reference in New Issue
Block a user