Skip to content

Commit 2fea827

Browse files
jimmbraddockparkerl
authored andcommitted
Add the isogram exercise (exercism#220)
* Add isogram exercise. * Change tests by principle: one test - one feature * Changed the order of words in the test names
1 parent 69cab9a commit 2fea827

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"hamming",
2626
"triangle",
2727
"beer-song",
28+
"isogram",
2829
"grade-school",
2930
"list-ops",
3031
"flatten-array",

exercises/isogram/example.exs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule Isogram do
2+
@doc """
3+
Determines if a word or sentence is an isogram
4+
"""
5+
@spec isogram?(String.t) :: boolean
6+
def isogram?(sentence) do
7+
codepoints = sentence
8+
|> String.downcase
9+
|> String.replace(~r/\s|-/u, "")
10+
|> String.codepoints
11+
12+
length(Enum.uniq(codepoints)) == length(codepoints)
13+
end
14+
15+
end

exercises/isogram/isogram.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule Isogram do
2+
@doc """
3+
Determines if a word or sentence is an isogram
4+
"""
5+
@spec isogram?(String.t) :: boolean
6+
def isogram?(sentence) do
7+
8+
end
9+
10+
end

exercises/isogram/isogram_test.exs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
2+
Code.load_file("isogram.exs", __DIR__)
3+
end
4+
5+
ExUnit.start
6+
ExUnit.configure exclude: :pending, trace: true
7+
8+
defmodule IsogramTest do
9+
use ExUnit.Case
10+
11+
test "isogram lowercase" do
12+
assert Isogram.isogram?("subdermatoglyphic")
13+
end
14+
15+
@tag :pending
16+
test "not isogram lowercase " do
17+
refute Isogram.isogram?("eleven")
18+
end
19+
20+
@tag :pending
21+
test "isogram uppercase" do
22+
assert Isogram.isogram?("DEMONSTRABLY")
23+
end
24+
25+
@tag :pending
26+
test "not isogram uppercase" do
27+
refute Isogram.isogram?("ALPHABET")
28+
end
29+
30+
@tag :pending
31+
test "isogram with dash" do
32+
assert Isogram.isogram?("hjelmqvist-gryb-zock-pfund-wax")
33+
end
34+
35+
@tag :pending
36+
test "not isogram with dash" do
37+
refute Isogram.isogram?("twenty-five")
38+
end
39+
40+
@tag :pending
41+
test "isogram with utf-8 letters" do
42+
assert Isogram.isogram?("heizölrückstoßabdämpfung")
43+
end
44+
45+
@tag :pending
46+
test "not isogram with utf-8 letters" do
47+
refute Isogram.isogram?("éléphant")
48+
end
49+
50+
@tag :pending
51+
test "phrase is isogram" do
52+
assert Isogram.isogram?("emily jung schwartzkopf")
53+
end
54+
55+
@tag :pending
56+
test "phrase is not isogram" do
57+
refute Isogram.isogram?("the quick brown fox")
58+
end
59+
60+
end

0 commit comments

Comments
 (0)