Initial commit

This commit is contained in:
2022-08-04 23:58:25 +02:00
commit ff1c36fc24
447 changed files with 9869 additions and 0 deletions

50
bob/.exercism/config.json Normal file
View File

@@ -0,0 +1,50 @@
{
"blurb": "Bob is a lackadaisical teenager. In conversation, his responses are very limited.",
"authors": [
"EduardoBautista"
],
"contributors": [
"andrewclarkson",
"ashleygwilliams",
"austinlyons",
"cjmochrie",
"cmccandless",
"coriolinus",
"cwhakes",
"EduardoBautista",
"efx",
"ErikSchierboom",
"etrepum",
"f3rn0s",
"IanWhitney",
"kytrinyx",
"leoyvens",
"lewisclement",
"lutostag",
"mkantor",
"nfiles",
"petertseng",
"pminten",
"rofrol",
"rpottsoh",
"stefanv",
"stringparser",
"vvv",
"xakon",
"ZapAnton"
],
"files": {
"solution": [
"src/lib.rs",
"Cargo.toml"
],
"test": [
"tests/bob.rs"
],
"example": [
".meta/example.rs"
]
},
"source": "Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial.",
"source_url": "http://pine.fm/LearnToProgram/?Chapter=06"
}

View File

@@ -0,0 +1 @@
{"track":"rust","exercise":"bob","id":"2ba266860b29447aafa6e7938191d672","url":"https://exercism.org/tracks/rust/exercises/bob","handle":"ArthurDanjou","is_requester":true,"auto_approve":false}

8
bob/.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
# Generated by Cargo
# will have compiled files and executables
/target/
**/*.rs.bk
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock

4
bob/Cargo.toml Normal file
View File

@@ -0,0 +1,4 @@
[package]
edition = "2021"
name = "bob"
version = "1.6.0"

85
bob/HELP.md Normal file
View File

@@ -0,0 +1,85 @@
# Help
## Running the tests
Execute the tests with:
```bash
$ cargo test
```
All but the first test have been ignored. After you get the first test to
pass, open the tests source file which is located in the `tests` directory
and remove the `#[ignore]` flag from the next test and get the tests to pass
again. Each separate test is a function with `#[test]` flag above it.
Continue, until you pass every test.
If you wish to run _only ignored_ tests without editing the tests source file, use:
```bash
$ cargo test -- --ignored
```
If you are using Rust 1.51 or later, you can run _all_ tests with
```bash
$ cargo test -- --include-ignored
```
To run a specific test, for example `some_test`, you can use:
```bash
$ cargo test some_test
```
If the specific test is ignored, use:
```bash
$ cargo test some_test -- --ignored
```
To learn more about Rust tests refer to the online [test documentation][rust-tests].
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
## Submitting your solution
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
This command will upload your solution to the Exercism website and print the solution page's URL.
It's possible to submit an incomplete solution which allows you to:
- See how others have completed the exercise
- Request help from a mentor
## Need to get help?
If you'd like help solving the exercise, check the following pages:
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
## Rust Installation
Refer to the [exercism help page][help-page] for Rust installation and learning
resources.
## Submitting the solution
Generally you should submit all files in which you implemented your solution (`src/lib.rs` in most cases). If you are using any external crates, please consider submitting the `Cargo.toml` file. This will make the review process faster and clearer.
## Feedback, Issues, Pull Requests
The GitHub [track repository][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].
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
[help-page]: https://exercism.org/tracks/rust/learning
[github]: https://github.com/exercism/rust
[contribution guide]: https://exercism.org/docs/community/contributors

62
bob/README.md Normal file
View File

@@ -0,0 +1,62 @@
# Bob
Welcome to Bob on Exercism's Rust Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
Bob answers 'Sure.' if you ask him a question, such as "How are you?".
He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals).
He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
He says 'Fine. Be that way!' if you address him without actually saying
anything.
He answers 'Whatever.' to anything else.
Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.
## Source
### Created by
- @EduardoBautista
### Contributed to by
- @andrewclarkson
- @ashleygwilliams
- @austinlyons
- @cjmochrie
- @cmccandless
- @coriolinus
- @cwhakes
- @EduardoBautista
- @efx
- @ErikSchierboom
- @etrepum
- @f3rn0s
- @IanWhitney
- @kytrinyx
- @leoyvens
- @lewisclement
- @lutostag
- @mkantor
- @nfiles
- @petertseng
- @pminten
- @rofrol
- @rpottsoh
- @stefanv
- @stringparser
- @vvv
- @xakon
- @ZapAnton
### Based on
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=06

14
bob/src/lib.rs Normal file
View File

@@ -0,0 +1,14 @@
fn is_yelling(message: &str) -> bool {
let have_letters: bool = message.chars().filter(|c| c.is_alphabetic()).count() > 0;
message.to_uppercase() == message && have_letters
}
pub fn reply(message: &str) -> &str {
match message.trim() {
m if m.trim().len() == 0 => "Fine. Be that way!",
m if m.ends_with("?") && is_yelling(m) => "Calm down, I know what I'm doing!",
m if m.ends_with("?") => "Sure.",
m if is_yelling(m) => "Whoa, chill out!",
_ => "Whatever."
}
}

190
bob/tests/bob.rs Normal file
View File

@@ -0,0 +1,190 @@
fn process_response_case(phrase: &str, expected_response: &str) {
assert_eq!(bob::reply(phrase), expected_response);
}
#[test]
/// stating something
fn test_stating_something() {
process_response_case("Tom-ay-to, tom-aaaah-to.", "Whatever.");
}
#[test]
#[ignore]
/// ending with whitespace
fn test_ending_with_whitespace() {
process_response_case("Okay if like my spacebar quite a bit? ", "Sure.");
}
#[test]
#[ignore]
/// shouting numbers
fn test_shouting_numbers() {
process_response_case("1, 2, 3 GO!", "Whoa, chill out!");
}
#[test]
#[ignore]
/// other whitespace
fn test_other_whitespace() {
process_response_case("\r\r ", "Fine. Be that way!");
}
#[test]
#[ignore]
/// shouting with special characters
fn test_shouting_with_special_characters() {
process_response_case(
"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!",
"Whoa, chill out!",
);
}
#[test]
#[ignore]
/// talking forcefully
fn test_talking_forcefully() {
process_response_case("Hi there!", "Whatever.");
}
#[test]
#[ignore]
/// prattling on
fn test_prattling_on() {
process_response_case("Wait! Hang on. Are you going to be OK?", "Sure.");
}
#[test]
#[ignore]
/// forceful question
fn test_forceful_question() {
process_response_case("WHAT'S GOING ON?", "Calm down, I know what I'm doing!");
}
#[test]
#[ignore]
/// shouting with no exclamation mark
fn test_shouting_with_no_exclamation_mark() {
process_response_case("I HATE THE DENTIST", "Whoa, chill out!");
}
#[test]
#[ignore]
/// asking gibberish
fn test_asking_gibberish() {
process_response_case("fffbbcbeab?", "Sure.");
}
#[test]
#[ignore]
/// question with no letters
fn test_question_with_no_letters() {
process_response_case("4?", "Sure.");
}
#[test]
#[ignore]
/// no letters
fn test_no_letters() {
process_response_case("1, 2, 3", "Whatever.");
}
#[test]
#[ignore]
/// statement containing question mark
fn test_statement_containing_question_mark() {
process_response_case("Ending with ? means a question.", "Whatever.");
}
//NEW
#[test]
#[ignore]
/// multiple line question
fn test_multiple_line_question() {
process_response_case(
"\rDoes this cryogenic chamber make me look fat?\rNo.",
"Whatever.",
);
}
#[test]
#[ignore]
/// non-question ending with whitespace
fn test_nonquestion_ending_with_whitespace() {
process_response_case(
"This is a statement ending with whitespace ",
"Whatever.",
);
}
#[test]
#[ignore]
/// shouting
fn test_shouting() {
process_response_case("WATCH OUT!", "Whoa, chill out!");
}
#[test]
#[ignore]
/// non-letters with question
fn test_nonletters_with_question() {
process_response_case(":) ?", "Sure.");
}
#[test]
#[ignore]
/// shouting gibberish
fn test_shouting_gibberish() {
process_response_case("FCECDFCAAB", "Whoa, chill out!");
}
#[test]
#[ignore]
/// asking a question
fn test_asking_a_question() {
process_response_case("Does this cryogenic chamber make me look fat?", "Sure.");
}
#[test]
#[ignore]
/// asking a numeric question
fn test_asking_a_numeric_question() {
process_response_case("You are, what, like 15?", "Sure.");
}
#[test]
#[ignore]
/// silence
fn test_silence() {
process_response_case("", "Fine. Be that way!");
}
#[test]
#[ignore]
/// starting with whitespace
fn test_starting_with_whitespace() {
process_response_case(" hmmmmmmm...", "Whatever.");
}
#[test]
#[ignore]
/// using acronyms in regular speech
fn test_using_acronyms_in_regular_speech() {
process_response_case(
"It's OK if you don't want to go work for NASA.",
"Whatever.",
);
}
#[test]
#[ignore]
/// alternate silence
fn test_alternate_silence() {
process_response_case(" ", "Fine. Be that way!");
}
#[test]
#[ignore]
/// prolonged silence
fn test_prolonged_silence() {
process_response_case(" ", "Fine. Be that way!");
}