Skip to content

bob: update to v1.1.0 #189

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

Merged
merged 1 commit into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions exercises/bob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Bob answers 'Sure.' if you ask him a question.

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

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.

Expand Down
15 changes: 12 additions & 3 deletions exercises/bob/uBobExample.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ interface
class function IsSilence(aStatement: string): Boolean; static;
class function IsYelling(aStatement: string): Boolean; static;
class function IsQuestion(aStatement: string): Boolean; static;
class function IsYellingQuestion(aStatement: string): Boolean; static;
public
class function Hey(aStatement: string): string; static;
class function Response(aStatement: string): string; static;
End;

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

class function TBob.IsYellingQuestion(aStatement: string): Boolean;
begin
result := IsQuestion(aStatement) and IsYelling(aStatement);
end;

class function TBob.IsQuestion(aStatement: string): Boolean;
begin
result := aStatement.Trim.EndsWith('?');
end;

class function TBob.Hey(aStatement: string): string;
class function TBob.Response(aStatement: string): string;
begin
if IsSilence(aStatement) then
result := 'Fine. Be that way!'
result := 'Fine. Be that way!'
else
if IsYellingQuestion(aStatement) then
result := 'Calm down, I know what I''m doing!'
else
if IsYelling(aStatement) then
result := 'Whoa, chill out!'
else
Expand Down
103 changes: 80 additions & 23 deletions exercises/bob/uBobTests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ interface
uses
DUnitX.TestFramework;

const
CanonicalVersion = '1.1.0';

type

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

[Test]
[Ignore]
procedure Asking_a_question_with_a_trailing_space;
procedure Asking_a_numeric_question;

[Test]
[Ignore]
procedure Asking_a_numeric_question;
procedure Asking_gibberish;

[Test]
[Ignore]
procedure Talking_forcefully;

[Test]
[Ignore]
procedure Using_acronyms_in_regular_search;
procedure Using_acronyms_in_regular_speech;

[Test]
[Ignore]
Expand Down Expand Up @@ -65,6 +68,10 @@ BobTests = class(TObject)
[Ignore]
procedure Statement_containing_question_mark;

[Test]
[Ignore]
procedure non_letters_with_question;

[Test]
[Ignore]
procedure Prattling_on;
Expand All @@ -77,102 +84,152 @@ BobTests = class(TObject)
[Ignore]
procedure Prolonged_silence;

[Test]
[Ignore]
procedure Alternate_silence;

[Test]
[Ignore]
procedure Multiple_line_question;

[Test]
[Ignore]
procedure Starting_with_whitespace;

[Test]
[Ignore]
procedure Ending_with_whitespace;

[Test]
[Ignore]
procedure Other_whitespace;

[Test]
[Ignore]
procedure Non_question_ending_with_whitespace;
end;

implementation
uses uBob;

procedure BobTests.Stating_something;
begin
assert.AreEqual('Whatever.', TBob.Hey('Tom-ay-to, tom-aaaah-to.'));
Assert.AreEqual('Whatever.', TBob.Response('Tom-ay-to, tom-aaaah-to.'));
end;

procedure BobTests.Shouting;
begin
assert.AreEqual('Whoa, chill out!', TBob.Hey('WATCH OUT!'));
Assert.AreEqual('Whoa, chill out!', TBob.Response('WATCH OUT!'));
end;

procedure BobTests.Asking_a_question;
begin
assert.AreEqual('Sure.', TBob.Hey('Does this cryogenic chamber make me look fat?'));
Assert.AreEqual('Sure.', TBob.Response('Does this cryogenic chamber make me look fat?'));
end;

procedure BobTests.Asking_gibberish;
begin
Assert.AreEqual('Sure.',TBob.Response('fffbbcbeab?'));
end;

procedure BobTests.Ending_with_whitespace;
begin
Assert.AreEqual('Sure.', TBob.Response('Okay if like my spacebar quite a bit? '));
end;

procedure BobTests.Asking_a_question_with_a_trailing_space;
procedure BobTests.Alternate_silence;
begin
assert.AreEqual('Sure.', TBob.Hey('Do I like my spacebar too much? '));
Assert.AreEqual('Fine. Be that way!', TBob.Response(#9#9#9#9#9#9#9#9#9#9));
end;

procedure BobTests.Asking_a_numeric_question;
begin
assert.AreEqual('Sure.', TBob.Hey('You are, what, like 15?'));
Assert.AreEqual('Sure.', TBob.Response('You are, what, like 15?'));
end;

procedure BobTests.Talking_forcefully;
begin
assert.AreEqual('Whatever.', TBob.Hey('Let''s go make out behind the gym!'));
Assert.AreEqual('Whatever.', TBob.Response('Let''s go make out behind the gym!'));
end;

procedure BobTests.Using_acronyms_in_regular_search;
procedure BobTests.Using_acronyms_in_regular_speech;
begin
assert.AreEqual('Whatever.', TBob.Hey('It''s OK if you don''t want to go to the DMV.'));
Assert.AreEqual('Whatever.', TBob.Response('It''s OK if you don''t want to go to the DMV.'));
end;

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

procedure BobTests.Shouting_numbers;
begin
assert.AreEqual('Whoa, chill out!', TBob.Hey('1, 2, 3 GO!'));
Assert.AreEqual('Whoa, chill out!', TBob.Response('1, 2, 3 GO!'));
end;

procedure BobTests.Only_numbers;
begin
assert.AreEqual('Whatever.', TBob.Hey('1, 2, 3'));
Assert.AreEqual('Whatever.', TBob.Response('1, 2, 3'));
end;

procedure BobTests.Other_whitespace;
begin
Assert.AreEqual('Fine. Be that way!', TBob.Response(#13#10 + ' ' + #9));
end;

procedure BobTests.Question_with_only_numbers;
begin
assert.AreEqual('Sure.', TBob.Hey('4?'));
Assert.AreEqual('Sure.', TBob.Response('4?'));
end;

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

procedure BobTests.Shouting_with_no_exclamation_mark;
begin
assert.AreEqual('Whoa, chill out!', TBob.Hey('I HATE YOU'));
Assert.AreEqual('Whoa, chill out!', TBob.Response('I HATE YOU'));
end;

procedure BobTests.Starting_with_whitespace;
begin
Assert.AreEqual('Whatever.', TBob.Response(' hmmmmmmm...'));
end;

procedure BobTests.Statement_containing_question_mark;
begin
assert.AreEqual('Whatever.', TBob.Hey('Ending with ? means a question.'));
Assert.AreEqual('Whatever.', TBob.Response('Ending with ? means a question.'));
end;

procedure BobTests.Prattling_on;
begin
assert.AreEqual('Sure.', TBob.Hey('Wait! Hang on. Are you going to be OK?'));
Assert.AreEqual('Sure.', TBob.Response('Wait! Hang on. Are you going to be OK?'));
end;

procedure BobTests.Silence;
begin
assert.AreEqual('Fine. Be that way!', TBob.Hey(''));
Assert.AreEqual('Fine. Be that way!', TBob.Response(''));
end;

procedure BobTests.Prolonged_silence;
begin
assert.AreEqual('Fine. Be that way!', TBob.Hey(' '));
Assert.AreEqual('Fine. Be that way!', TBob.Response(' '));
end;

procedure BobTests.Multiple_line_question;
begin
assert.AreEqual('Whatever.', TBob.Hey('Does this cryogenic chamber make me look fat?' + #13#10 + 'no'));
Assert.AreEqual('Whatever.', TBob.Response('Does this cryogenic chamber make me look fat?' + #13#10 + 'no'));
end;

procedure BobTests.non_letters_with_question;
begin
Assert.AreEqual('Sure.', TBob.Response(':) ?'));
end;

procedure BobTests.Non_question_ending_with_whitespace;
begin
Assert.AreEqual('Whatever.', TBob.Response('This is a statement ending with whitespace '));
end;

initialization
Expand Down