Skip to content

Commit 34baa63

Browse files
authored
Merge pull request #459 from Insti/alliesauce-isogram-completed
Add isogram
2 parents c28125f + 8fa2d7a commit 34baa63

File tree

6 files changed

+153
-1
lines changed

6 files changed

+153
-1
lines changed

config.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
"connect",
8585
"list-ops",
8686
"diamond",
87-
"all-your-base"
87+
"all-your-base",
88+
"isogram"
8889
],
8990
"exercises": [
9091
{
@@ -566,6 +567,12 @@
566567
"difficulty": 1,
567568
"topics": [
568569
]
570+
},
571+
{
572+
"slug": "isogram",
573+
"difficulty": 1,
574+
"topics": [
575+
]
569576
}
570577
],
571578
"deprecated": [

exercises/isogram/.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

exercises/isogram/example.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module BookKeeping
2+
VERSION = 1
3+
end
4+
5+
class Isogram
6+
def self.is_isogram?(str)
7+
letters = str.downcase.gsub(/[[:punct:]]| /, '').chars
8+
letters == letters.uniq
9+
end
10+
end

exercises/isogram/example.tt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env ruby
2+
# encoding: utf-8
3+
gem 'minitest', '>= 5.0.0'
4+
require 'minitest/autorun'
5+
require_relative 'isogram'
6+
7+
# Common test data version: <%= sha1 %>
8+
class IsogramTest < Minitest::Test<% test_cases.each do |test_case| %>
9+
def <%= test_case.name %>
10+
<%= test_case.skip %>
11+
string = '<%= test_case.input %>'
12+
<%= test_case.assertion %> Isogram.is_isogram?(string)
13+
end
14+
<% end %>
15+
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>
16+
def test_bookkeeping
17+
skip
18+
assert_equal <%= version.next %>, BookKeeping::VERSION
19+
end
20+
end

exercises/isogram/isogram_test.rb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env ruby
2+
# encoding: utf-8
3+
gem 'minitest', '>= 5.0.0'
4+
require 'minitest/autorun'
5+
require_relative 'isogram'
6+
7+
# Common test data version: 3dfde31
8+
class IsogramTest < Minitest::Test
9+
def test_duplicates
10+
11+
string = 'duplicates'
12+
assert Isogram.is_isogram?(string)
13+
end
14+
15+
def test_eleven
16+
skip
17+
string = 'eleven'
18+
refute Isogram.is_isogram?(string)
19+
end
20+
21+
def test_subdermatoglyphic
22+
skip
23+
string = 'subdermatoglyphic'
24+
assert Isogram.is_isogram?(string)
25+
end
26+
27+
def test_alphabet
28+
skip
29+
string = 'Alphabet'
30+
refute Isogram.is_isogram?(string)
31+
end
32+
33+
def test_thumbscrew_japingly
34+
skip
35+
string = 'thumbscrew-japingly'
36+
assert Isogram.is_isogram?(string)
37+
end
38+
39+
def test_hjelmqvist_gryb_zock_pfund_wax
40+
skip
41+
string = 'Hjelmqvist-Gryb-Zock-Pfund-Wax'
42+
assert Isogram.is_isogram?(string)
43+
end
44+
45+
def test_heizölrückstoßabdämpfung
46+
skip
47+
string = 'Heizölrückstoßabdämpfung'
48+
assert Isogram.is_isogram?(string)
49+
end
50+
51+
def test_the_quick_brown_fox
52+
skip
53+
string = 'the quick brown fox'
54+
refute Isogram.is_isogram?(string)
55+
end
56+
57+
def test_emily_jung_schwartzkopf
58+
skip
59+
string = 'Emily Jung Schwartzkopf'
60+
assert Isogram.is_isogram?(string)
61+
end
62+
63+
def test_éléphant
64+
skip
65+
string = 'éléphant'
66+
refute Isogram.is_isogram?(string)
67+
end
68+
69+
# Problems in exercism evolve over time, as we find better ways to ask
70+
# questions.
71+
# The version number refers to the version of the problem you solved,
72+
# not your solution.
73+
#
74+
# Define a constant named VERSION inside of the top level BookKeeping
75+
# module, which may be placed near the end of your file.
76+
#
77+
# In your file, it will look like this:
78+
#
79+
# module BookKeeping
80+
# VERSION = 1 # Where the version number matches the one in the test.
81+
# end
82+
#
83+
# If you are curious, read more about constants on RubyDoc:
84+
# http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html
85+
86+
def test_bookkeeping
87+
skip
88+
assert_equal 1, BookKeeping::VERSION
89+
end
90+
end

lib/isogram_cases.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class IsogramCase < OpenStruct
2+
3+
def name
4+
format('test_%s', description)
5+
end
6+
7+
def description
8+
input.downcase.gsub(/[ -]/,'_')
9+
end
10+
11+
def assertion
12+
expected ? 'assert' : 'refute'
13+
end
14+
15+
def skip
16+
'skip' unless index.zero?
17+
end
18+
end
19+
20+
IsogramCases = proc do |data|
21+
JSON.parse(data)['cases'].map.with_index do |row, i|
22+
IsogramCase.new(row.merge('index' => i))
23+
end
24+
end

0 commit comments

Comments
 (0)