-
Notifications
You must be signed in to change notification settings - Fork 523
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
Twofer exercise #520
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c895576
added twofer exercise
4603799
Added twofer to config.json
32d3708
Requested changes.Same Version in all files. removed underscore prefix.
878f73a
Merge branch 'master' into twofer
coriolinus 6b09683
Apply 'configlet fmt'
coriolinus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
/target/ | ||
**/*.rs.bk | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
name = "twofer" | ||
version = "1.2.0" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
|
||
#[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."); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will consider the following part of #520 (comment) to comprise this explanation:
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.