Skip to content

Commit 6dcecb3

Browse files
author
marisa
committed
fix(strings): Move Strings before Structs
Closes #204.
1 parent dcfb427 commit 6dcecb3

File tree

3 files changed

+59
-59
lines changed

3 files changed

+59
-59
lines changed

exercises/test2.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
// test2.rs
22
// This is a test for the following sections:
3-
// - Tests
3+
// - Strings
44

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!
99

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);
1215
}
1316

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());
2728
}

exercises/test3.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
// strings3.rs
1+
// test3.rs
22
// This is a test for the following sections:
3-
// - Strings
3+
// - Tests
44

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!
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 :)
99

10-
fn string_slice(arg: &str) {
11-
println!("{}", arg);
12-
}
13-
fn string(arg: String) {
14-
println!("{}", arg);
10+
pub fn times_two(num: i32) -> i32 {
11+
num * 2
1512
}
1613

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());
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+
}
2827
}

info.toml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ mode = "test"
8686
path = "exercises/structs/structs2.rs"
8787
mode = "test"
8888

89+
# STRINGS
90+
91+
[[exercises]]
92+
path = "exercises/strings/strings1.rs"
93+
mode = "compile"
94+
95+
[[exercises]]
96+
path = "exercises/strings/strings2.rs"
97+
mode = "compile"
98+
99+
# TEST 2
100+
101+
[[exercises]]
102+
path = "exercises/test2.rs"
103+
mode = "compile"
104+
89105
# ENUMS
90106

91107
[[exercises]]
@@ -114,27 +130,11 @@ mode = "test"
114130
path = "exercises/tests/tests3.rs"
115131
mode = "test"
116132

117-
# TEST 2
118-
119-
[[exercises]]
120-
path = "exercises/test2.rs"
121-
mode = "test"
122-
123-
# STRINGS
124-
125-
[[exercises]]
126-
path = "exercises/strings/strings1.rs"
127-
mode = "compile"
128-
129-
[[exercises]]
130-
path = "exercises/strings/strings2.rs"
131-
mode = "compile"
132-
133133
# TEST 3
134134

135135
[[exercises]]
136136
path = "exercises/test3.rs"
137-
mode = "compile"
137+
mode = "test"
138138

139139
# MODULES
140140

0 commit comments

Comments
 (0)