|
1 | 1 | // test2.rs |
2 | 2 | // This is a test for the following sections: |
3 | | -// - Tests |
| 3 | +// - Strings |
4 | 4 |
|
5 | | -// This test isn't testing our function -- make it do that in such a way that |
6 | | -// the test passes. Then write a second test that tests that we get the result |
7 | | -// we expect to get when we call `times_two` with a negative number. |
8 | | -// No hints, you can do this :) |
| 5 | +// Ok, here are a bunch of values-- some are `Strings`, some are `&strs`. Your |
| 6 | +// task is to call one of these two functions on each value depending on what |
| 7 | +// you think each value is. That is, add either `string_slice` or `string` |
| 8 | +// before the parentheses on each line. If you're right, it will compile! |
9 | 9 |
|
10 | | -pub fn times_two(num: i32) -> i32 { |
11 | | - num * 2 |
| 10 | +fn string_slice(arg: &str) { |
| 11 | + println!("{}", arg); |
| 12 | +} |
| 13 | +fn string(arg: String) { |
| 14 | + println!("{}", arg); |
12 | 15 | } |
13 | 16 |
|
14 | | -#[cfg(test)] |
15 | | -mod tests { |
16 | | - use super::*; |
17 | | - |
18 | | - #[test] |
19 | | - fn returns_twice_of_positive_numbers() { |
20 | | - assert_eq!(times_two(4), ???); |
21 | | - } |
22 | | - |
23 | | - #[test] |
24 | | - fn returns_twice_of_negative_numbers() { |
25 | | - // TODO write an assert for `times_two(-4)` |
26 | | - } |
| 17 | +fn main() { |
| 18 | + ("blue"); |
| 19 | + ("red".to_string()); |
| 20 | + (String::from("hi")); |
| 21 | + ("rust is fun!".to_owned()); |
| 22 | + ("nice weather".into()); |
| 23 | + (format!("Interpolation {}", "Station")); |
| 24 | + (&String::from("abc")[0..1]); |
| 25 | + (" hello there ".trim()); |
| 26 | + ("Happy Monday!".to_string().replace("Mon", "Tues")); |
| 27 | + ("mY sHiFt KeY iS sTiCkY".to_lowercase()); |
27 | 28 | } |
0 commit comments