parent
dcfb427b09
commit
6dcecb38a4
|
@ -1,27 +1,28 @@
|
||||||
// test2.rs
|
// test2.rs
|
||||||
// This is a test for the following sections:
|
// 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
|
// Ok, here are a bunch of values-- some are `Strings`, some are `&strs`. Your
|
||||||
// the test passes. Then write a second test that tests that we get the result
|
// task is to call one of these two functions on each value depending on what
|
||||||
// we expect to get when we call `times_two` with a negative number.
|
// you think each value is. That is, add either `string_slice` or `string`
|
||||||
// No hints, you can do this :)
|
// before the parentheses on each line. If you're right, it will compile!
|
||||||
|
|
||||||
pub fn times_two(num: i32) -> i32 {
|
fn string_slice(arg: &str) {
|
||||||
num * 2
|
println!("{}", arg);
|
||||||
|
}
|
||||||
|
fn string(arg: String) {
|
||||||
|
println!("{}", arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
fn main() {
|
||||||
mod tests {
|
("blue");
|
||||||
use super::*;
|
("red".to_string());
|
||||||
|
(String::from("hi"));
|
||||||
#[test]
|
("rust is fun!".to_owned());
|
||||||
fn returns_twice_of_positive_numbers() {
|
("nice weather".into());
|
||||||
assert_eq!(times_two(4), ???);
|
(format!("Interpolation {}", "Station"));
|
||||||
}
|
(&String::from("abc")[0..1]);
|
||||||
|
(" hello there ".trim());
|
||||||
#[test]
|
("Happy Monday!".to_string().replace("Mon", "Tues"));
|
||||||
fn returns_twice_of_negative_numbers() {
|
("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
||||||
// TODO write an assert for `times_two(-4)`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,27 @@
|
||||||
// strings3.rs
|
// test3.rs
|
||||||
// This is a test for the following sections:
|
// This is a test for the following sections:
|
||||||
// - Strings
|
// - Tests
|
||||||
|
|
||||||
// Ok, here are a bunch of values-- some are `Strings`, some are `&strs`. Your
|
// This test isn't testing our function -- make it do that in such a way that
|
||||||
// task is to call one of these two functions on each value depending on what
|
// the test passes. Then write a second test that tests that we get the result
|
||||||
// you think each value is. That is, add either `string_slice` or `string`
|
// we expect to get when we call `times_two` with a negative number.
|
||||||
// before the parentheses on each line. If you're right, it will compile!
|
// No hints, you can do this :)
|
||||||
|
|
||||||
fn string_slice(arg: &str) {
|
pub fn times_two(num: i32) -> i32 {
|
||||||
println!("{}", arg);
|
num * 2
|
||||||
}
|
|
||||||
fn string(arg: String) {
|
|
||||||
println!("{}", arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
#[cfg(test)]
|
||||||
("blue");
|
mod tests {
|
||||||
("red".to_string());
|
use super::*;
|
||||||
(String::from("hi"));
|
|
||||||
("rust is fun!".to_owned());
|
#[test]
|
||||||
("nice weather".into());
|
fn returns_twice_of_positive_numbers() {
|
||||||
(format!("Interpolation {}", "Station"));
|
assert_eq!(times_two(4), ???);
|
||||||
(&String::from("abc")[0..1]);
|
}
|
||||||
(" hello there ".trim());
|
|
||||||
("Happy Monday!".to_string().replace("Mon", "Tues"));
|
#[test]
|
||||||
("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
fn returns_twice_of_negative_numbers() {
|
||||||
|
// TODO write an assert for `times_two(-4)`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
34
info.toml
34
info.toml
|
@ -86,6 +86,22 @@ mode = "test"
|
||||||
path = "exercises/structs/structs2.rs"
|
path = "exercises/structs/structs2.rs"
|
||||||
mode = "test"
|
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
|
# ENUMS
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
|
@ -114,27 +130,11 @@ mode = "test"
|
||||||
path = "exercises/tests/tests3.rs"
|
path = "exercises/tests/tests3.rs"
|
||||||
mode = "test"
|
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
|
# TEST 3
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
path = "exercises/test3.rs"
|
path = "exercises/test3.rs"
|
||||||
mode = "compile"
|
mode = "test"
|
||||||
|
|
||||||
# MODULES
|
# MODULES
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue