Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twofer exercise #520

Merged
merged 5 commits into from
May 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions exercises/twofer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

/target/
**/*.rs.bk
Cargo.lock
5 changes: 5 additions & 0 deletions exercises/twofer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "twofer"
version = "1.2.0"

[dependencies]
47 changes: 47 additions & 0 deletions exercises/twofer/README.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions exercises/twofer/example.rs
Original file line number Diff line number Diff line change
@@ -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),
}
}
3 changes: 3 additions & 0 deletions exercises/twofer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn twofer(name: &str)-> String {
unimplemented!("One for {}, one for me.", name);
}
19 changes: 19 additions & 0 deletions exercises/twofer/tests/two-fer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extern crate twofer;
use twofer::twofer;

#[test]
fn empty_string() {
assert_eq!(twofer(""), "One for you, one for me.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain to me that such a comment is actually not necessary for certain reasons (don't confuse the student with unnecessary information, etc., I'll let the person who explains it to me come up with the reason why it's not necessary)

I will consider the following part of #520 (comment) to comprise this explanation:

thought about this exercise as some kind of second "hello world" and introduction to pattern matching. In my opinion the Result/Some stuff is a more advanced concept and covered in later exercises.

I counter that it is still possible to say as a comment in this test "using the empty string as a sentinel value is not preferred in Rust since we have better ways to express the absence of a value, but we will learn those ways later in the track" without having to specify what those alternative ways are.

I cannot comment on what is the best way to teach students these concepts; I would have to spent time on improving my skills and knowledge before I can effectively spend time to think about and comment on how to teach.

Thus, it does not make sense for me to require any changes before this PR should be merged.

}

#[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.");
}