diff --git a/config.json b/config.json index db6508620..36c1f9e40 100644 --- a/config.json +++ b/config.json @@ -18,6 +18,17 @@ "println" ] }, + { + "slug": "twofer", + "uuid": "c6631a2c-4632-11e8-842f-0ed5f89f718b", + "core": false, + "unlocked_by": null, + "difficulty": 1, + "topics": [ + "match", + "strings" + ] + }, { "slug": "gigasecond", "uuid": "f880b1ef-8f66-41f3-bb89-f39a4ed592a2", diff --git a/exercises/twofer/.gitignore b/exercises/twofer/.gitignore new file mode 100644 index 000000000..143b1ca01 --- /dev/null +++ b/exercises/twofer/.gitignore @@ -0,0 +1,4 @@ + +/target/ +**/*.rs.bk +Cargo.lock diff --git a/exercises/twofer/Cargo.toml b/exercises/twofer/Cargo.toml new file mode 100644 index 000000000..c80ccc6a8 --- /dev/null +++ b/exercises/twofer/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "twofer" +version = "1.2.0" + +[dependencies] diff --git a/exercises/twofer/README.md b/exercises/twofer/README.md new file mode 100644 index 000000000..a450fd0c1 --- /dev/null +++ b/exercises/twofer/README.md @@ -0,0 +1,47 @@ +## Two-fer + +`Two-fer` or `2-fer` is short for two for one. One for you and one for me. + +```text +"One for X, one for me." +``` + +When X is a name or "you". + +If the given name is "Alice", the result should be "One for Alice, one for me." +If no name is given, the result should be "One for you, one for me." + +## Rust Installation + +Refer to the [exercism help page][help-page] for Rust installation and learning +resources. + +## Writing the Code + +Execute the tests with: + +```bash +$ cargo test +``` + +All but the first test have been ignored. After you get the first test to +pass, remove the ignore flag (`#[ignore]`) from the next test and get the tests +to pass again. The test file is located in the `tests` directory. You can +also remove the ignore flag from all the tests to get them to run all at once +if you wish. + +Make sure to read the [Modules](https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html) chapter if you +haven't already, it will help you with organizing your files. + +## Feedback, Issues, Pull Requests + +The [exercism/rust](https://github.com/exercism/rust) repository on GitHub is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the rust track team are happy to help! + +If you want to know more about Exercism, take a look at the [contribution guide](https://github.com/exercism/docs/blob/master/contributing-to-language-tracks/README.md). + +[help-page]: http://exercism.io/languages/rust +[modules]: https://doc.rust-lang.org/book/second-edition/ch07-00-modules.html +[cargo]: https://doc.rust-lang.org/book/second-edition/ch14-00-more-about-cargo.html + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. \ No newline at end of file diff --git a/exercises/twofer/example.rs b/exercises/twofer/example.rs new file mode 100644 index 000000000..e9154f40e --- /dev/null +++ b/exercises/twofer/example.rs @@ -0,0 +1,6 @@ +pub fn twofer(name: &str)-> String { + match name { + "" => "One for you, one for me.".to_string(), + _ => format!("One for {}, one for me.",name), + } +} \ No newline at end of file diff --git a/exercises/twofer/src/lib.rs b/exercises/twofer/src/lib.rs new file mode 100644 index 000000000..b0f6fccb8 --- /dev/null +++ b/exercises/twofer/src/lib.rs @@ -0,0 +1,3 @@ +pub fn twofer(name: &str)-> String { + unimplemented!("One for {}, one for me.", name); +} \ No newline at end of file diff --git a/exercises/twofer/tests/two-fer.rs b/exercises/twofer/tests/two-fer.rs new file mode 100644 index 000000000..ad8bea40e --- /dev/null +++ b/exercises/twofer/tests/two-fer.rs @@ -0,0 +1,19 @@ +extern crate twofer; +use twofer::twofer; + +#[test] +fn empty_string() { + assert_eq!(twofer(""), "One for you, one for me."); +} + +#[test] +#[ignore] +fn alice() { + assert_eq!(twofer("Alice"), "One for Alice, one for me."); +} + +#[test] +#[ignore] +fn bob() { + assert_eq!(twofer("Bob"), "One for Bob, one for me."); +} \ No newline at end of file