Skip to content

Commit

Permalink
Add exercise: bob (JuliaLang#10)
Browse files Browse the repository at this point in the history
* Add exercise: bob

* bob: Remove unicode tests

* bob: Add topic to config
  • Loading branch information
SaschaMann authored Jan 28, 2017
1 parent 62cb58c commit d403fe9
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@
"sorting",
"filtering"
]
},
{
"slug": "bob",
"difficulty": 2,
"topics": [
"strings",
"unicode",
"control-flow (if-else statements)"
]
}
],
"deprecated": [
Expand Down
3 changes: 3 additions & 0 deletions exercises/bob/bob.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function bob(stimulus::AbstractString)

end
30 changes: 30 additions & 0 deletions exercises/bob/example.jl
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
70 changes: 70 additions & 0 deletions exercises/bob/runtests.jl
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

0 comments on commit d403fe9

Please sign in to comment.