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.
Merge pull request JuliaLang#22 from andrej-makarov-skrt/ex-scrabble-…
…score Add exercise: scrabble-score
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
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,9 @@ | ||
function score(str::AbstractString) | ||
rank = Dict('a'=>1, 'e'=>1, 'i'=>1, 'o'=>1, 'u'=>1, 'l'=>1, | ||
'n'=>1, 'r'=>1, 's'=>1, 't'=>1, 'd'=>2, 'g'=>2, | ||
'b'=>3, 'c'=>3, 'm'=>3, 'p'=>3, 'f'=>4, 'h'=>4, | ||
'v'=>4, 'w'=>4, 'y'=>4, 'k'=>5, 'j'=>8, 'x'=>8, | ||
'q'=>10, 'z'=>10) | ||
length(str) == 0 && return 0 | ||
mapreduce(x->get(rank, x, 0), +, lowercase(str)) | ||
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,51 @@ | ||
using Base.Test | ||
|
||
include("scrabble-score.jl") | ||
|
||
@testset "lowercase letter" begin | ||
@test score("a") == 1 | ||
end | ||
|
||
@testset "uppercase letter" begin | ||
@test score("A") == 1 | ||
end | ||
|
||
@testset "valuable letter" begin | ||
@test score("f") == 4 | ||
end | ||
|
||
@testset "short word" begin | ||
@test score("at") == 2 | ||
end | ||
|
||
@testset "short, valuable word" begin | ||
@test score("zoo") == 12 | ||
end | ||
|
||
@testset "medium word" begin | ||
@test score("street") == 6 | ||
end | ||
|
||
@testset "medium, valuable word" begin | ||
@test score("quirky") == 22 | ||
end | ||
|
||
@testset "long, mixed-case word" begin | ||
@test score("OxyphenButazone") == 41 | ||
end | ||
|
||
@testset "english-like word" begin | ||
@test score("pinata") == 8 | ||
end | ||
|
||
@testset "non-english letter is not scored" begin | ||
@test score("piñata") == 7 | ||
end | ||
|
||
@testset "empty input" begin | ||
@test score("") == 0 | ||
end | ||
|
||
@testset "entire alphabet available" begin | ||
@test score("abcdefghijklmnopqrstuvwxyz") == 87 | ||
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,3 @@ | ||
function score(str::AbstractString) | ||
|
||
end |