forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add exercise: bob * bob: Remove unicode tests * bob: Add topic to config
- Loading branch information
1 parent
62cb58c
commit d403fe9
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function bob(stimulus::AbstractString) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function bob(stimulus::AbstractString) | ||
stimulus = strip(stimulus) | ||
|
||
if issilence(stimulus) | ||
return "Fine. Be that way!" | ||
elseif isshouting(stimulus) | ||
return "Whoa, chill out!" | ||
elseif isquestion(stimulus) | ||
return "Sure." | ||
else | ||
return "Whatever." | ||
end | ||
end | ||
|
||
issilence(stimulus::AbstractString) = isempty(stimulus) | ||
isquestion(stimulus::AbstractString) = endswith(stimulus, '?') | ||
|
||
function isshouting(stimulus::AbstractString) | ||
isupper(stimulus) && return true | ||
!any(isalpha, stimulus) && return false | ||
|
||
for c in stimulus | ||
# ignore all non-letter chars | ||
if isalpha(c) && !isupper(c) | ||
return false | ||
end | ||
end | ||
|
||
return true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using Base.Test | ||
|
||
include("bob.jl") | ||
|
||
questions = ( | ||
"Does this cryogenic chamber make me look fat?", | ||
"You are, what, like 15?", | ||
"fffbbcbeab?", | ||
"4?", ":) ?", | ||
"Wait! Hang on. Are you going to be OK?", | ||
"Okay if like my spacebar quite a bit? ", | ||
) | ||
|
||
yells = ( | ||
"WATCH OUT!", | ||
"FCECDFCAAB", | ||
"WHAT THE HELL WERE YOU THINKING?", | ||
"1, 2, 3 GO!", | ||
"ZOMG THE %^*@#\$(*^ ZOMBIES ARE COMING!!11!!1!", | ||
"I HATE YOU", | ||
) | ||
|
||
silences = ( | ||
"", | ||
" ", | ||
"\t\t\t\t\t\t\t\t\t\t", | ||
"\n\r \t", | ||
) | ||
|
||
miscs = ( | ||
"Tom-ay-to, tom-aaaah-to.", | ||
"Let's go make out behind the gym!", | ||
"It's OK if you don't want to go to the DMV.", | ||
"1, 2, 3", | ||
"Ending with ? means a question.", | ||
"\nDoes this cryogenic chamber make me look fat?\nno", | ||
" hmmmmmmm...", | ||
"This is a statement ending with whitespace ", | ||
) | ||
|
||
response = Dict( | ||
:question => "Sure.", | ||
:yelling => "Whoa, chill out!", | ||
:silence => "Fine. Be that way!", | ||
:misc => "Whatever." | ||
) | ||
|
||
@testset "questions" begin | ||
@testset "$question" for question in questions | ||
@test bob(question) == response[:question] | ||
end | ||
end | ||
|
||
@testset "yelling" begin | ||
@testset "$yell" for yell in yells | ||
@test bob(yell) == response[:yelling] | ||
end | ||
end | ||
|
||
@testset "silence" begin | ||
@testset "$silence" for silence in silences | ||
@test bob(silence) == response[:silence] | ||
end | ||
end | ||
|
||
@testset "misc" begin | ||
@testset "$misc" for misc in miscs | ||
@test bob(misc) == response[:misc] | ||
end | ||
end |