fix(strings): Move Strings before Structs

Closes #204.
This commit is contained in:
marisa 2019-11-11 13:46:42 +01:00
parent dcfb427b09
commit 6dcecb38a4
3 changed files with 59 additions and 59 deletions

View File

@ -1,27 +1,28 @@
// test2.rs
// This is a test for the following sections:
// - Tests
// - Strings
// 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 :)
// 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
// you think each value is. That is, add either `string_slice` or `string`
// before the parentheses on each line. If you're right, it will compile!
pub fn times_two(num: i32) -> i32 {
num * 2
fn string_slice(arg: &str) {
println!("{}", arg);
}
fn string(arg: String) {
println!("{}", arg);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn returns_twice_of_positive_numbers() {
assert_eq!(times_two(4), ???);
}
#[test]
fn returns_twice_of_negative_numbers() {
// TODO write an assert for `times_two(-4)`
}
fn main() {
("blue");
("red".to_string());
(String::from("hi"));
("rust is fun!".to_owned());
("nice weather".into());
(format!("Interpolation {}", "Station"));
(&String::from("abc")[0..1]);
(" hello there ".trim());
("Happy Monday!".to_string().replace("Mon", "Tues"));
("mY sHiFt KeY iS sTiCkY".to_lowercase());
}

View File

@ -1,28 +1,27 @@
// strings3.rs
// test3.rs
// This is a test for the following sections:
// - Strings
// - Tests
// 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
// you think each value is. That is, add either `string_slice` or `string`
// before the parentheses on each line. If you're right, it will compile!
// 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 :)
fn string_slice(arg: &str) {
println!("{}", arg);
}
fn string(arg: String) {
println!("{}", arg);
pub fn times_two(num: i32) -> i32 {
num * 2
}
fn main() {
("blue");
("red".to_string());
(String::from("hi"));
("rust is fun!".to_owned());
("nice weather".into());
(format!("Interpolation {}", "Station"));
(&String::from("abc")[0..1]);
(" hello there ".trim());
("Happy Monday!".to_string().replace("Mon", "Tues"));
("mY sHiFt KeY iS sTiCkY".to_lowercase());
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn returns_twice_of_positive_numbers() {
assert_eq!(times_two(4), ???);
}
#[test]
fn returns_twice_of_negative_numbers() {
// TODO write an assert for `times_two(-4)`
}
}

View File

@ -86,6 +86,22 @@ mode = "test"
path = "exercises/structs/structs2.rs"
mode = "test"
# STRINGS
[[exercises]]
path = "exercises/strings/strings1.rs"
mode = "compile"
[[exercises]]
path = "exercises/strings/strings2.rs"
mode = "compile"
# TEST 2
[[exercises]]
path = "exercises/test2.rs"
mode = "compile"
# ENUMS
[[exercises]]
@ -114,27 +130,11 @@ mode = "test"
path = "exercises/tests/tests3.rs"
mode = "test"
# TEST 2
[[exercises]]
path = "exercises/test2.rs"
mode = "test"
# STRINGS
[[exercises]]
path = "exercises/strings/strings1.rs"
mode = "compile"
[[exercises]]
path = "exercises/strings/strings2.rs"
mode = "compile"
# TEST 3
[[exercises]]
path = "exercises/test3.rs"
mode = "compile"
mode = "test"
# MODULES