aboutsummaryrefslogtreecommitdiff
path: root/bob
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2020-12-26 17:48:38 +0000
committerFederico Igne <git@federicoigne.com>2021-11-03 18:55:08 +0000
commit02481656966b0a8dfc95cf3c22bcc049660ff7d4 (patch)
tree8e39798fcaf27931d91c2088423fd4e97adcfc2d /bob
parent4e2052c4d792540c2f742b2c2a081b11117ed41d (diff)
downloadexercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.tar.gz
exercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.zip
Move Rust exercises in a subdirectory
Diffstat (limited to 'bob')
-rw-r--r--bob/.exercism/metadata.json1
-rw-r--r--bob/.gitignore8
-rw-r--r--bob/Cargo.toml4
-rw-r--r--bob/README.md96
-rw-r--r--bob/src/lib.rs75
-rw-r--r--bob/tests/bob.rs179
6 files changed, 0 insertions, 363 deletions
diff --git a/bob/.exercism/metadata.json b/bob/.exercism/metadata.json
deleted file mode 100644
index c9dfddb..0000000
--- a/bob/.exercism/metadata.json
+++ /dev/null
@@ -1 +0,0 @@
1{"track":"rust","exercise":"bob","id":"4e53ee4ebf414ac3b9da60e7011c04f9","url":"https://exercism.io/my/solutions/4e53ee4ebf414ac3b9da60e7011c04f9","handle":"dyamon","is_requester":true,"auto_approve":false} \ No newline at end of file
diff --git a/bob/.gitignore b/bob/.gitignore
deleted file mode 100644
index db7f315..0000000
--- a/bob/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
1# Generated by Cargo
2# will have compiled files and executables
3/target/
4**/*.rs.bk
5
6# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
8Cargo.lock
diff --git a/bob/Cargo.toml b/bob/Cargo.toml
deleted file mode 100644
index 34a7fbf..0000000
--- a/bob/Cargo.toml
+++ /dev/null
@@ -1,4 +0,0 @@
1[package]
2edition = "2018"
3name = "bob"
4version = "1.6.0"
diff --git a/bob/README.md b/bob/README.md
deleted file mode 100644
index dd84948..0000000
--- a/bob/README.md
+++ /dev/null
@@ -1,96 +0,0 @@
1# Bob
2
3Bob is a lackadaisical teenager. In conversation, his responses are very limited.
4
5Bob answers 'Sure.' if you ask him a question, such as "How are you?".
6
7He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals).
8
9He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
10
11He says 'Fine. Be that way!' if you address him without actually saying
12anything.
13
14He answers 'Whatever.' to anything else.
15
16Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English.
17
18## Rust Installation
19
20Refer to the [exercism help page][help-page] for Rust installation and learning
21resources.
22
23## Writing the Code
24
25Execute the tests with:
26
27```bash
28$ cargo test
29```
30
31All but the first test have been ignored. After you get the first test to
32pass, open the tests source file which is located in the `tests` directory
33and remove the `#[ignore]` flag from the next test and get the tests to pass
34again. Each separate test is a function with `#[test]` flag above it.
35Continue, until you pass every test.
36
37If you wish to run all ignored tests without editing the tests source file, use:
38
39```bash
40$ cargo test -- --ignored
41```
42
43To run a specific test, for example `some_test`, you can use:
44
45```bash
46$ cargo test some_test
47```
48
49If the specific test is ignored use:
50
51```bash
52$ cargo test some_test -- --ignored
53```
54
55To learn more about Rust tests refer to the [online test documentation][rust-tests]
56
57Make sure to read the [Modules][modules] chapter if you
58haven't already, it will help you with organizing your files.
59
60## Further improvements
61
62After you have solved the exercise, please consider using the additional utilities, described in the [installation guide](https://exercism.io/tracks/rust/installation), to further refine your final solution.
63
64To format your solution, inside the solution directory use
65
66```bash
67cargo fmt
68```
69
70To see, if your solution contains some common ineffective use cases, inside the solution directory use
71
72```bash
73cargo clippy --all-targets
74```
75
76## Submitting the solution
77
78Generally 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.
79
80## Feedback, Issues, Pull Requests
81
82The [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!
83
84If 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).
85
86[help-page]: https://exercism.io/tracks/rust/learning
87[modules]: https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html
88[cargo]: https://doc.rust-lang.org/book/ch14-00-more-about-cargo.html
89[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
90
91## Source
92
93Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=06](http://pine.fm/LearnToProgram/?Chapter=06)
94
95## Submitting Incomplete Solutions
96It's possible to submit an incomplete solution so you can see how others have completed the exercise.
diff --git a/bob/src/lib.rs b/bob/src/lib.rs
deleted file mode 100644
index ae18a3d..0000000
--- a/bob/src/lib.rs
+++ /dev/null
@@ -1,75 +0,0 @@
1/* The solution consists of an implementation of a simple Finite State Automaton whose states and
2 * transition messages are represented by the `State` and `Message` enums.
3 *
4 * `process(State, Message) -> State` represents the main transition function for the FSA. This
5 * allows us to compute the answer with a single visit of the input string.
6 *
7 * Note: some duplicate states (`QuestLow`, `ElseLow`) are needed in order to remember whether we
8 * have seen a lowercase character already or not. This is probably not the minimal number of
9 * states required to solve the problem.
10 */
11enum State { Nothing, QuestLow, Quest, Yell, YellQ, ElseLow, Else }
12enum Message { Whitespace, Upper, Lower, Symbol, Question }
13
14fn to_message(c: char) -> Message {
15 match c as u8 {
16 0..=32 => Message::Whitespace, // All controll characters are considered whitespace
17 63 => Message::Question,
18 65..=90 => Message::Upper,
19 97..=122 => Message::Lower,
20 _ => Message::Symbol // Anything else (numbers incl.) is a symbol
21 }
22}
23
24fn process(s: State, m: Message) -> State {
25 match s {
26 State::Nothing => match m {
27 Message::Whitespace => s,
28 Message::Upper => State::Yell,
29 Message::Lower => State::ElseLow,
30 Message::Question => State::Quest,
31 Message::Symbol => State::Else
32 },
33 State::QuestLow => match m {
34 Message::Whitespace | Message::Question => s,
35 _ => State::ElseLow
36 },
37 State::Quest => match m {
38 Message::Upper => State::Yell,
39 Message::Lower => State::ElseLow,
40 Message::Symbol => State::Else,
41 _ => s
42 },
43 State::Yell => match m {
44 Message::Lower => State::ElseLow,
45 Message::Question => State::YellQ,
46 _ => s
47 },
48 State::YellQ => match m {
49 Message::Symbol | Message::Upper => State::Yell,
50 Message::Lower => State::ElseLow,
51 _ => s
52 },
53 State::ElseLow => match m {
54 Message::Question => State::QuestLow,
55 _ => s
56 },
57 State::Else => match m {
58 Message::Upper => State::Yell,
59 Message::Lower => State::ElseLow,
60 Message::Question => State::Quest,
61 _ => s
62 }
63 }
64}
65
66pub fn reply(message: &str) -> &str {
67 let state = message.chars().fold(State::Nothing, |s, c| process(s,to_message(c)));
68 match state {
69 State::Nothing => "Fine. Be that way!",
70 State::QuestLow | State::Quest => "Sure.",
71 State::Yell => "Whoa, chill out!",
72 State::YellQ => "Calm down, I know what I'm doing!",
73 _ => "Whatever."
74 }
75}
diff --git a/bob/tests/bob.rs b/bob/tests/bob.rs
deleted file mode 100644
index b6221eb..0000000
--- a/bob/tests/bob.rs
+++ /dev/null
@@ -1,179 +0,0 @@
1fn process_response_case(phrase: &str, expected_response: &str) {
2 assert_eq!(bob::reply(phrase), expected_response);
3}
4
5#[test]
6/// stating something
7fn test_stating_something() {
8 process_response_case("Tom-ay-to, tom-aaaah-to.", "Whatever.");
9}
10
11
12#[test]
13/// ending with whitespace
14fn test_ending_with_whitespace() {
15 process_response_case("Okay if like my spacebar quite a bit? ", "Sure.");
16}
17
18
19#[test]
20/// shouting numbers
21fn test_shouting_numbers() {
22 process_response_case("1, 2, 3 GO!", "Whoa, chill out!");
23}
24
25
26#[test]
27/// other whitespace
28fn test_other_whitespace() {
29 process_response_case("\r\r ", "Fine. Be that way!");
30}
31
32
33#[test]
34/// shouting with special characters
35fn test_shouting_with_special_characters() {
36 process_response_case("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!", "Whoa, chill out!");
37}
38
39
40#[test]
41/// talking forcefully
42fn test_talking_forcefully() {
43 process_response_case("Hi there!", "Whatever.");
44}
45
46
47#[test]
48/// prattling on
49fn test_prattling_on() {
50 process_response_case("Wait! Hang on. Are you going to be OK?", "Sure.");
51}
52
53
54#[test]
55/// forceful question
56fn test_forceful_question() {
57 process_response_case("WHAT'S GOING ON?", "Calm down, I know what I'm doing!");
58}
59
60
61#[test]
62/// shouting with no exclamation mark
63fn test_shouting_with_no_exclamation_mark() {
64 process_response_case("I HATE THE DENTIST", "Whoa, chill out!");
65}
66
67
68#[test]
69/// asking gibberish
70fn test_asking_gibberish() {
71 process_response_case("fffbbcbeab?", "Sure.");
72}
73
74
75#[test]
76/// question with no letters
77fn test_question_with_no_letters() {
78 process_response_case("4?", "Sure.");
79}
80
81
82#[test]
83/// no letters
84fn test_no_letters() {
85 process_response_case("1, 2, 3", "Whatever.");
86}
87
88
89#[test]
90/// statement containing question mark
91fn test_statement_containing_question_mark() {
92 process_response_case("Ending with ? means a question.", "Whatever.");
93}
94
95
96//NEW
97#[test]
98/// multiple line question
99fn test_multiple_line_question() {
100 process_response_case("\rDoes this cryogenic chamber make me look fat?\rNo.", "Whatever.");
101}
102
103
104#[test]
105/// non-question ending with whitespace
106fn test_nonquestion_ending_with_whitespace() {
107 process_response_case("This is a statement ending with whitespace ", "Whatever.");
108}
109
110
111#[test]
112/// shouting
113fn test_shouting() {
114 process_response_case("WATCH OUT!", "Whoa, chill out!");
115}
116
117
118#[test]
119/// non-letters with question
120fn test_nonletters_with_question() {
121 process_response_case(":) ?", "Sure.");
122}
123
124
125#[test]
126/// shouting gibberish
127fn test_shouting_gibberish() {
128 process_response_case("FCECDFCAAB", "Whoa, chill out!");
129}
130
131
132#[test]
133/// asking a question
134fn test_asking_a_question() {
135 process_response_case("Does this cryogenic chamber make me look fat?", "Sure.");
136}
137
138
139#[test]
140/// asking a numeric question
141fn test_asking_a_numeric_question() {
142 process_response_case("You are, what, like 15?", "Sure.");
143}
144
145
146#[test]
147/// silence
148fn test_silence() {
149 process_response_case("", "Fine. Be that way!");
150}
151
152
153#[test]
154/// starting with whitespace
155fn test_starting_with_whitespace() {
156 process_response_case(" hmmmmmmm...", "Whatever.");
157}
158
159
160#[test]
161/// using acronyms in regular speech
162fn test_using_acronyms_in_regular_speech() {
163 process_response_case("It's OK if you don't want to go work for NASA.", "Whatever.");
164}
165
166
167#[test]
168/// alternate silence
169fn test_alternate_silence() {
170 process_response_case(" ", "Fine. Be that way!");
171}
172
173
174#[test]
175/// prolonged silence
176fn test_prolonged_silence() {
177 process_response_case(" ", "Fine. Be that way!");
178}
179