Skip to content

Commit fb1e2bc

Browse files
author
callaghan
committed
added some rust tasks
1 parent fb90edf commit fb1e2bc

31 files changed

+1750
-1
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.gitignore
22
*.json
3-
.idea
3+
.idea
4+
.exercism
5+
target

rust/bob/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
edition = "2021"
3+
name = "bob"
4+
version = "1.6.0"

rust/bob/HELP.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Help
2+
3+
## Running the tests
4+
5+
Execute the tests with:
6+
7+
```bash
8+
$ cargo test
9+
```
10+
11+
All but the first test have been ignored. After you get the first test to
12+
pass, open the tests source file which is located in the `tests` directory
13+
and remove the `#[ignore]` flag from the next test and get the tests to pass
14+
again. Each separate test is a function with `#[test]` flag above it.
15+
Continue, until you pass every test.
16+
17+
If you wish to run _only ignored_ tests without editing the tests source file, use:
18+
19+
```bash
20+
$ cargo test -- --ignored
21+
```
22+
23+
If you are using Rust 1.51 or later, you can run _all_ tests with
24+
25+
```bash
26+
$ cargo test -- --include-ignored
27+
```
28+
29+
To run a specific test, for example `some_test`, you can use:
30+
31+
```bash
32+
$ cargo test some_test
33+
```
34+
35+
If the specific test is ignored, use:
36+
37+
```bash
38+
$ cargo test some_test -- --ignored
39+
```
40+
41+
To learn more about Rust tests refer to the online [test documentation][rust-tests].
42+
43+
[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
44+
45+
## Submitting your solution
46+
47+
You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
48+
This command will upload your solution to the Exercism website and print the solution page's URL.
49+
50+
It's possible to submit an incomplete solution which allows you to:
51+
52+
- See how others have completed the exercise
53+
- Request help from a mentor
54+
55+
## Need to get help?
56+
57+
If you'd like help solving the exercise, check the following pages:
58+
59+
- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
60+
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
61+
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
62+
63+
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
64+
65+
## Rust Installation
66+
67+
Refer to the [exercism help page][help-page] for Rust installation and learning
68+
resources.
69+
70+
## Submitting the solution
71+
72+
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.
73+
74+
## Feedback, Issues, Pull Requests
75+
76+
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!
77+
78+
If you want to know more about Exercism, take a look at the [contribution guide].
79+
80+
## Submitting Incomplete Solutions
81+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
82+
83+
[help-page]: https://exercism.org/tracks/rust/learning
84+
[github]: https://github.com/exercism/rust
85+
[contribution guide]: https://exercism.org/docs/community/contributors

rust/bob/README.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Bob
2+
3+
Welcome to Bob on Exercism's Rust Track.
4+
If you need help running the tests or submitting your code, check out `HELP.md`.
5+
6+
## Introduction
7+
8+
Bob is a [lackadaisical][] teenager.
9+
He likes to think that he's very cool.
10+
And he definitely doesn't get excited about things.
11+
That wouldn't be cool.
12+
13+
When people talk to him, his responses are pretty limited.
14+
15+
[lackadaisical]: https://www.collinsdictionary.com/dictionary/english/lackadaisical
16+
17+
## Instructions
18+
19+
Your task is to determine what Bob will reply to someone when they say something to him or ask him a question.
20+
21+
Bob only ever answers one of five things:
22+
23+
- **"Sure."**
24+
This is his response if you ask him a question, such as "How are you?"
25+
The convention used for questions is that it ends with a question mark.
26+
- **"Whoa, chill out!"**
27+
This is his answer if you YELL AT HIM.
28+
The convention used for yelling is ALL CAPITAL LETTERS.
29+
- **"Calm down, I know what I'm doing!"**
30+
This is what he says if you yell a question at him.
31+
- **"Fine. Be that way!"**
32+
This is how he responds to silence.
33+
The convention used for silence is nothing, or various combinations of whitespace characters.
34+
- **"Whatever."**
35+
This is what he answers to anything else.
36+
37+
## Source
38+
39+
### Created by
40+
41+
- @EduardoBautista
42+
43+
### Contributed to by
44+
45+
- @andrewclarkson
46+
- @ashleygwilliams
47+
- @austinlyons
48+
- @cjmochrie
49+
- @cmccandless
50+
- @coriolinus
51+
- @cwhakes
52+
- @EduardoBautista
53+
- @efx
54+
- @ErikSchierboom
55+
- @etrepum
56+
- @f3rn0s
57+
- @IanWhitney
58+
- @kytrinyx
59+
- @leoyvens
60+
- @lewisclement
61+
- @lutostag
62+
- @mkantor
63+
- @nfiles
64+
- @petertseng
65+
- @pminten
66+
- @rofrol
67+
- @rpottsoh
68+
- @stefanv
69+
- @stringparser
70+
- @vvv
71+
- @xakon
72+
- @ZapAnton
73+
74+
### Based on
75+
76+
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=06

rust/bob/src/lib.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
pub fn reply(message: &str) -> &str {
2+
let copy_message = message.clone();
3+
let clean = remove_special_characters_iter(copy_message);
4+
let captial = is_uppercase_string(clean.as_str());
5+
6+
if message.trim().len() == 0 {
7+
return "Fine. Be that way!";
8+
} else if captial {
9+
if message.trim().chars().last().unwrap() == '?' {
10+
return "Calm down, I know what I'm doing!";
11+
} else {
12+
return "Whoa, chill out!";
13+
}
14+
} else if message.trim().chars().last().unwrap() == '?' {
15+
return "Sure.";
16+
}
17+
return "Whatever.";
18+
}
19+
20+
fn remove_special_characters_iter(s: &str) -> String {
21+
s.chars().filter(|c| c.is_alphabetic()).collect()
22+
}
23+
24+
fn is_uppercase_string(s: &str) -> bool {
25+
if s.len() == 0 {
26+
return false;
27+
}
28+
s.chars().all(|c| c.is_uppercase())
29+
}

rust/bob/tests/bob.rs

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
fn process_response_case(phrase: &str, expected_response: &str) {
2+
assert_eq!(bob::reply(phrase), expected_response);
3+
}
4+
5+
#[test]
6+
/// stating something
7+
fn test_stating_something() {
8+
process_response_case("Tom-ay-to, tom-aaaah-to.", "Whatever.");
9+
}
10+
11+
#[test]
12+
#[ignore]
13+
/// ending with whitespace
14+
fn test_ending_with_whitespace() {
15+
process_response_case("Okay if like my spacebar quite a bit? ", "Sure.");
16+
}
17+
18+
#[test]
19+
#[ignore]
20+
/// shouting numbers
21+
fn test_shouting_numbers() {
22+
process_response_case("1, 2, 3 GO!", "Whoa, chill out!");
23+
}
24+
25+
#[test]
26+
#[ignore]
27+
/// other whitespace
28+
fn test_other_whitespace() {
29+
process_response_case("\r\r ", "Fine. Be that way!");
30+
}
31+
32+
#[test]
33+
#[ignore]
34+
/// shouting with special characters
35+
fn test_shouting_with_special_characters() {
36+
process_response_case(
37+
"ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!",
38+
"Whoa, chill out!",
39+
);
40+
}
41+
42+
#[test]
43+
#[ignore]
44+
/// talking forcefully
45+
fn test_talking_forcefully() {
46+
process_response_case("Hi there!", "Whatever.");
47+
}
48+
49+
#[test]
50+
#[ignore]
51+
/// prattling on
52+
fn test_prattling_on() {
53+
process_response_case("Wait! Hang on. Are you going to be OK?", "Sure.");
54+
}
55+
56+
#[test]
57+
#[ignore]
58+
/// forceful question
59+
fn test_forceful_question() {
60+
process_response_case("WHAT'S GOING ON?", "Calm down, I know what I'm doing!");
61+
}
62+
63+
#[test]
64+
#[ignore]
65+
/// shouting with no exclamation mark
66+
fn test_shouting_with_no_exclamation_mark() {
67+
process_response_case("I HATE THE DENTIST", "Whoa, chill out!");
68+
}
69+
70+
#[test]
71+
#[ignore]
72+
/// asking gibberish
73+
fn test_asking_gibberish() {
74+
process_response_case("fffbbcbeab?", "Sure.");
75+
}
76+
77+
#[test]
78+
#[ignore]
79+
/// question with no letters
80+
fn test_question_with_no_letters() {
81+
process_response_case("4?", "Sure.");
82+
}
83+
84+
#[test]
85+
#[ignore]
86+
/// no letters
87+
fn test_no_letters() {
88+
process_response_case("1, 2, 3", "Whatever.");
89+
}
90+
91+
#[test]
92+
#[ignore]
93+
/// statement containing question mark
94+
fn test_statement_containing_question_mark() {
95+
process_response_case("Ending with ? means a question.", "Whatever.");
96+
}
97+
98+
//NEW
99+
#[test]
100+
#[ignore]
101+
/// multiple line question
102+
fn test_multiple_line_question() {
103+
process_response_case(
104+
"\rDoes this cryogenic chamber make me look fat?\rNo.",
105+
"Whatever.",
106+
);
107+
}
108+
109+
#[test]
110+
#[ignore]
111+
/// non-question ending with whitespace
112+
fn test_nonquestion_ending_with_whitespace() {
113+
process_response_case(
114+
"This is a statement ending with whitespace ",
115+
"Whatever.",
116+
);
117+
}
118+
119+
#[test]
120+
#[ignore]
121+
/// shouting
122+
fn test_shouting() {
123+
process_response_case("WATCH OUT!", "Whoa, chill out!");
124+
}
125+
126+
#[test]
127+
#[ignore]
128+
/// non-letters with question
129+
fn test_nonletters_with_question() {
130+
process_response_case(":) ?", "Sure.");
131+
}
132+
133+
#[test]
134+
#[ignore]
135+
/// shouting gibberish
136+
fn test_shouting_gibberish() {
137+
process_response_case("FCECDFCAAB", "Whoa, chill out!");
138+
}
139+
140+
#[test]
141+
#[ignore]
142+
/// asking a question
143+
fn test_asking_a_question() {
144+
process_response_case("Does this cryogenic chamber make me look fat?", "Sure.");
145+
}
146+
147+
#[test]
148+
#[ignore]
149+
/// asking a numeric question
150+
fn test_asking_a_numeric_question() {
151+
process_response_case("You are, what, like 15?", "Sure.");
152+
}
153+
154+
#[test]
155+
#[ignore]
156+
/// silence
157+
fn test_silence() {
158+
process_response_case("", "Fine. Be that way!");
159+
}
160+
161+
#[test]
162+
#[ignore]
163+
/// starting with whitespace
164+
fn test_starting_with_whitespace() {
165+
process_response_case(" hmmmmmmm...", "Whatever.");
166+
}
167+
168+
#[test]
169+
#[ignore]
170+
/// using acronyms in regular speech
171+
fn test_using_acronyms_in_regular_speech() {
172+
process_response_case(
173+
"It's OK if you don't want to go work for NASA.",
174+
"Whatever.",
175+
);
176+
}
177+
178+
#[test]
179+
#[ignore]
180+
/// alternate silence
181+
fn test_alternate_silence() {
182+
process_response_case(" ", "Fine. Be that way!");
183+
}
184+
185+
#[test]
186+
#[ignore]
187+
/// prolonged silence
188+
fn test_prolonged_silence() {
189+
process_response_case(" ", "Fine. Be that way!");
190+
}

0 commit comments

Comments
 (0)