Skip to content

Commit 40d2870

Browse files
authored
bob: update to v1.1.0 (#189)
Updated test suite and example solution to conform to v1.1.0 of test data.
1 parent 928eb58 commit 40d2870

File tree

3 files changed

+94
-26
lines changed

3 files changed

+94
-26
lines changed

exercises/bob/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Bob answers 'Sure.' if you ask him a question.
66

77
He answers 'Whoa, chill out!' if you yell at him.
88

9+
He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
10+
911
He says 'Fine. Be that way!' if you address him without actually saying
1012
anything.
1113

exercises/bob/uBobExample.pas

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ interface
88
class function IsSilence(aStatement: string): Boolean; static;
99
class function IsYelling(aStatement: string): Boolean; static;
1010
class function IsQuestion(aStatement: string): Boolean; static;
11+
class function IsYellingQuestion(aStatement: string): Boolean; static;
1112
public
12-
class function Hey(aStatement: string): string; static;
13+
class function Response(aStatement: string): string; static;
1314
End;
1415

1516
implementation
@@ -25,16 +26,24 @@ class function TBob.IsYelling(aStatement: string): Boolean;
2526
result := (aStatement.ToUpper = aStatement) and TRegEx.IsMatch(aStatement, '[a-zA-Z]+');
2627
end;
2728

29+
class function TBob.IsYellingQuestion(aStatement: string): Boolean;
30+
begin
31+
result := IsQuestion(aStatement) and IsYelling(aStatement);
32+
end;
33+
2834
class function TBob.IsQuestion(aStatement: string): Boolean;
2935
begin
3036
result := aStatement.Trim.EndsWith('?');
3137
end;
3238

33-
class function TBob.Hey(aStatement: string): string;
39+
class function TBob.Response(aStatement: string): string;
3440
begin
3541
if IsSilence(aStatement) then
36-
result := 'Fine. Be that way!'
42+
result := 'Fine. Be that way!'
3743
else
44+
if IsYellingQuestion(aStatement) then
45+
result := 'Calm down, I know what I''m doing!'
46+
else
3847
if IsYelling(aStatement) then
3948
result := 'Whoa, chill out!'
4049
else

exercises/bob/uBobTests.pas

Lines changed: 80 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ interface
44
uses
55
DUnitX.TestFramework;
66

7+
const
8+
CanonicalVersion = '1.1.0';
9+
710
type
811

912
[TestFixture]
@@ -23,19 +26,19 @@ BobTests = class(TObject)
2326

2427
[Test]
2528
[Ignore]
26-
procedure Asking_a_question_with_a_trailing_space;
29+
procedure Asking_a_numeric_question;
2730

2831
[Test]
2932
[Ignore]
30-
procedure Asking_a_numeric_question;
33+
procedure Asking_gibberish;
3134

3235
[Test]
3336
[Ignore]
3437
procedure Talking_forcefully;
3538

3639
[Test]
3740
[Ignore]
38-
procedure Using_acronyms_in_regular_search;
41+
procedure Using_acronyms_in_regular_speech;
3942

4043
[Test]
4144
[Ignore]
@@ -65,6 +68,10 @@ BobTests = class(TObject)
6568
[Ignore]
6669
procedure Statement_containing_question_mark;
6770

71+
[Test]
72+
[Ignore]
73+
procedure non_letters_with_question;
74+
6875
[Test]
6976
[Ignore]
7077
procedure Prattling_on;
@@ -77,102 +84,152 @@ BobTests = class(TObject)
7784
[Ignore]
7885
procedure Prolonged_silence;
7986

87+
[Test]
88+
[Ignore]
89+
procedure Alternate_silence;
90+
8091
[Test]
8192
[Ignore]
8293
procedure Multiple_line_question;
94+
95+
[Test]
96+
[Ignore]
97+
procedure Starting_with_whitespace;
98+
99+
[Test]
100+
[Ignore]
101+
procedure Ending_with_whitespace;
102+
103+
[Test]
104+
[Ignore]
105+
procedure Other_whitespace;
106+
107+
[Test]
108+
[Ignore]
109+
procedure Non_question_ending_with_whitespace;
83110
end;
84111

85112
implementation
86113
uses uBob;
87114

88115
procedure BobTests.Stating_something;
89116
begin
90-
assert.AreEqual('Whatever.', TBob.Hey('Tom-ay-to, tom-aaaah-to.'));
117+
Assert.AreEqual('Whatever.', TBob.Response('Tom-ay-to, tom-aaaah-to.'));
91118
end;
92119

93120
procedure BobTests.Shouting;
94121
begin
95-
assert.AreEqual('Whoa, chill out!', TBob.Hey('WATCH OUT!'));
122+
Assert.AreEqual('Whoa, chill out!', TBob.Response('WATCH OUT!'));
96123
end;
97124

98125
procedure BobTests.Asking_a_question;
99126
begin
100-
assert.AreEqual('Sure.', TBob.Hey('Does this cryogenic chamber make me look fat?'));
127+
Assert.AreEqual('Sure.', TBob.Response('Does this cryogenic chamber make me look fat?'));
128+
end;
129+
130+
procedure BobTests.Asking_gibberish;
131+
begin
132+
Assert.AreEqual('Sure.',TBob.Response('fffbbcbeab?'));
133+
end;
134+
135+
procedure BobTests.Ending_with_whitespace;
136+
begin
137+
Assert.AreEqual('Sure.', TBob.Response('Okay if like my spacebar quite a bit? '));
101138
end;
102139

103-
procedure BobTests.Asking_a_question_with_a_trailing_space;
140+
procedure BobTests.Alternate_silence;
104141
begin
105-
assert.AreEqual('Sure.', TBob.Hey('Do I like my spacebar too much? '));
142+
Assert.AreEqual('Fine. Be that way!', TBob.Response(#9#9#9#9#9#9#9#9#9#9));
106143
end;
107144

108145
procedure BobTests.Asking_a_numeric_question;
109146
begin
110-
assert.AreEqual('Sure.', TBob.Hey('You are, what, like 15?'));
147+
Assert.AreEqual('Sure.', TBob.Response('You are, what, like 15?'));
111148
end;
112149

113150
procedure BobTests.Talking_forcefully;
114151
begin
115-
assert.AreEqual('Whatever.', TBob.Hey('Let''s go make out behind the gym!'));
152+
Assert.AreEqual('Whatever.', TBob.Response('Let''s go make out behind the gym!'));
116153
end;
117154

118-
procedure BobTests.Using_acronyms_in_regular_search;
155+
procedure BobTests.Using_acronyms_in_regular_speech;
119156
begin
120-
assert.AreEqual('Whatever.', TBob.Hey('It''s OK if you don''t want to go to the DMV.'));
157+
Assert.AreEqual('Whatever.', TBob.Response('It''s OK if you don''t want to go to the DMV.'));
121158
end;
122159

123160
procedure BobTests.Forceful_questions;
124161
begin
125-
assert.AreEqual('Whoa, chill out!', TBob.Hey('WHAT THE HELL WERE YOU THINKING?'));
162+
Assert.AreEqual('Calm down, I know what I''m doing!', TBob.Response('WHAT THE HELL WERE YOU THINKING?'));
126163
end;
127164

128165
procedure BobTests.Shouting_numbers;
129166
begin
130-
assert.AreEqual('Whoa, chill out!', TBob.Hey('1, 2, 3 GO!'));
167+
Assert.AreEqual('Whoa, chill out!', TBob.Response('1, 2, 3 GO!'));
131168
end;
132169

133170
procedure BobTests.Only_numbers;
134171
begin
135-
assert.AreEqual('Whatever.', TBob.Hey('1, 2, 3'));
172+
Assert.AreEqual('Whatever.', TBob.Response('1, 2, 3'));
173+
end;
174+
175+
procedure BobTests.Other_whitespace;
176+
begin
177+
Assert.AreEqual('Fine. Be that way!', TBob.Response(#13#10 + ' ' + #9));
136178
end;
137179

138180
procedure BobTests.Question_with_only_numbers;
139181
begin
140-
assert.AreEqual('Sure.', TBob.Hey('4?'));
182+
Assert.AreEqual('Sure.', TBob.Response('4?'));
141183
end;
142184

143185
procedure BobTests.Shouting_with_special_characters;
144186
begin
145-
assert.AreEqual('Whoa, chill out!', TBob.Hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!'));
187+
Assert.AreEqual('Whoa, chill out!', TBob.Response('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!'));
146188
end;
147189

148190
procedure BobTests.Shouting_with_no_exclamation_mark;
149191
begin
150-
assert.AreEqual('Whoa, chill out!', TBob.Hey('I HATE YOU'));
192+
Assert.AreEqual('Whoa, chill out!', TBob.Response('I HATE YOU'));
193+
end;
194+
195+
procedure BobTests.Starting_with_whitespace;
196+
begin
197+
Assert.AreEqual('Whatever.', TBob.Response(' hmmmmmmm...'));
151198
end;
152199

153200
procedure BobTests.Statement_containing_question_mark;
154201
begin
155-
assert.AreEqual('Whatever.', TBob.Hey('Ending with ? means a question.'));
202+
Assert.AreEqual('Whatever.', TBob.Response('Ending with ? means a question.'));
156203
end;
157204

158205
procedure BobTests.Prattling_on;
159206
begin
160-
assert.AreEqual('Sure.', TBob.Hey('Wait! Hang on. Are you going to be OK?'));
207+
Assert.AreEqual('Sure.', TBob.Response('Wait! Hang on. Are you going to be OK?'));
161208
end;
162209

163210
procedure BobTests.Silence;
164211
begin
165-
assert.AreEqual('Fine. Be that way!', TBob.Hey(''));
212+
Assert.AreEqual('Fine. Be that way!', TBob.Response(''));
166213
end;
167214

168215
procedure BobTests.Prolonged_silence;
169216
begin
170-
assert.AreEqual('Fine. Be that way!', TBob.Hey(' '));
217+
Assert.AreEqual('Fine. Be that way!', TBob.Response(' '));
171218
end;
172219

173220
procedure BobTests.Multiple_line_question;
174221
begin
175-
assert.AreEqual('Whatever.', TBob.Hey('Does this cryogenic chamber make me look fat?' + #13#10 + 'no'));
222+
Assert.AreEqual('Whatever.', TBob.Response('Does this cryogenic chamber make me look fat?' + #13#10 + 'no'));
223+
end;
224+
225+
procedure BobTests.non_letters_with_question;
226+
begin
227+
Assert.AreEqual('Sure.', TBob.Response(':) ?'));
228+
end;
229+
230+
procedure BobTests.Non_question_ending_with_whitespace;
231+
begin
232+
Assert.AreEqual('Whatever.', TBob.Response('This is a statement ending with whitespace '));
176233
end;
177234

178235
initialization

0 commit comments

Comments
 (0)