Skip to content

Commit

Permalink
fix(strings): Move Strings before Structs
Browse files Browse the repository at this point in the history
Closes #204.
  • Loading branch information
marisa committed Nov 11, 2019
1 parent dcfb427 commit 6dcecb3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 59 deletions.
41 changes: 21 additions & 20 deletions exercises/test2.rs
Original file line number Diff line number Diff line change
@@ -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());
}
43 changes: 21 additions & 22 deletions exercises/test3.rs
Original file line number Diff line number Diff line change
@@ -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)`
}
}
34 changes: 17 additions & 17 deletions info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6dcecb3

Please sign in to comment.