Skip to content

Commit 9a73ca5

Browse files
authored
Merge pull request #575 from hilary/add-generator-for-etl
Carry #549: Add generator for etl
2 parents 21c54f4 + c6402c6 commit 9a73ca5

File tree

5 files changed

+117
-30
lines changed

5 files changed

+117
-30
lines changed

exercises/etl/.meta/.version

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

exercises/etl/etl_test.rb

Lines changed: 82 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,110 @@
33
require 'minitest/autorun'
44
require_relative 'etl'
55

6-
class TransformTest < Minitest::Test
7-
def test_transform_one_value
8-
old = { 1 => ['A'] }
9-
expected = { 'a' => 1 }
10-
6+
# Common test data version: ca9ed58
7+
class EtlTest < Minitest::Test
8+
def test_a_single_letter
9+
# skip
10+
old = {
11+
1 => ["A"]
12+
}
13+
expected = {
14+
'a' => 1
15+
}
1116
assert_equal expected, ETL.transform(old)
1217
end
1318

14-
def test_transform_more_values
19+
def test_single_score_with_multiple_letters
1520
skip
16-
old = { 1 => %w(A E I O U) }
17-
expected = { 'a' => 1, 'e' => 1, 'i' => 1, 'o' => 1, 'u' => 1 }
18-
21+
old = {
22+
1 => ["A", "E", "I", "O", "U"]
23+
}
24+
expected = {
25+
'a' => 1,
26+
'e' => 1,
27+
'i' => 1,
28+
'o' => 1,
29+
'u' => 1
30+
}
1931
assert_equal expected, ETL.transform(old)
2032
end
2133

22-
def test_more_keys
34+
def test_multiple_scores_with_multiple_letters
2335
skip
24-
old = { 1 => %w(A E), 2 => %w(D G) }
36+
old = {
37+
1 => ["A", "E"],
38+
2 => ["D", "G"]
39+
}
2540
expected = {
2641
'a' => 1,
27-
'e' => 1,
2842
'd' => 2,
43+
'e' => 1,
2944
'g' => 2
3045
}
31-
3246
assert_equal expected, ETL.transform(old)
3347
end
3448

35-
def test_full_dataset
49+
def test_multiple_scores_with_differing_numbers_of_letters
3650
skip
3751
old = {
38-
1 => %w(A E I O U L N R S T),
39-
2 => %w(D G),
40-
3 => %w(B C M P),
41-
4 => %w(F H V W Y),
42-
5 => %w(K),
43-
8 => %w(J X),
44-
10 => %w(Q Z)
52+
1 => ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"],
53+
2 => ["D", "G"],
54+
3 => ["B", "C", "M", "P"],
55+
4 => ["F", "H", "V", "W", "Y"],
56+
5 => ["K"],
57+
8 => ["J", "X"],
58+
10 => ["Q", "Z"]
4559
}
46-
4760
expected = {
48-
'a' => 1, 'b' => 3, 'c' => 3, 'd' => 2, 'e' => 1,
49-
'f' => 4, 'g' => 2, 'h' => 4, 'i' => 1, 'j' => 8,
50-
'k' => 5, 'l' => 1, 'm' => 3, 'n' => 1, 'o' => 1,
51-
'p' => 3, 'q' => 10, 'r' => 1, 's' => 1, 't' => 1,
52-
'u' => 1, 'v' => 4, 'w' => 4, 'x' => 8, 'y' => 4,
61+
'a' => 1,
62+
'b' => 3,
63+
'c' => 3,
64+
'd' => 2,
65+
'e' => 1,
66+
'f' => 4,
67+
'g' => 2,
68+
'h' => 4,
69+
'i' => 1,
70+
'j' => 8,
71+
'k' => 5,
72+
'l' => 1,
73+
'm' => 3,
74+
'n' => 1,
75+
'o' => 1,
76+
'p' => 3,
77+
'q' => 10,
78+
'r' => 1,
79+
's' => 1,
80+
't' => 1,
81+
'u' => 1,
82+
'v' => 4,
83+
'w' => 4,
84+
'x' => 8,
85+
'y' => 4,
5386
'z' => 10
5487
}
55-
5688
assert_equal expected, ETL.transform(old)
5789
end
90+
91+
# Problems in exercism evolve over time, as we find better ways to ask
92+
# questions.
93+
# The version number refers to the version of the problem you solved,
94+
# not your solution.
95+
#
96+
# Define a constant named VERSION inside of the top level BookKeeping
97+
# module, which may be placed near the end of your file.
98+
#
99+
# In your file, it will look like this:
100+
#
101+
# module BookKeeping
102+
# VERSION = 1 # Where the version number matches the one in the test.
103+
# end
104+
#
105+
# If you are curious, read more about constants on RubyDoc:
106+
# http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html
107+
108+
def test_bookkeeping
109+
skip
110+
assert_equal 1, BookKeeping::VERSION
111+
end
58112
end

exercises/etl/example.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
module BookKeeping
2+
VERSION = 1
3+
end
4+
15
class ETL
26
def self.transform(old)
37
data = {}

lib/etl_cases.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'generator/exercise_cases'
2+
3+
class EtlCase < ExerciseCase
4+
def workload
5+
indent_lines([
6+
"old = {\n #{format(input)}\n }",
7+
"expected = {\n #{format(expected)}\n }",
8+
"assert_equal expected, ETL.transform(old)"
9+
], 4)
10+
end
11+
12+
private
13+
14+
def format(obj)
15+
case
16+
when obj.respond_to?(:each_pair)
17+
indent_lines(
18+
obj.each_with_object([]) {|(k, v), string| string << "#{format(k)} => #{format(v)}" },
19+
6,
20+
",\n"
21+
)
22+
when obj.respond_to?(:each) then obj
23+
when obj.to_s =~ /\d+/ then obj.to_i
24+
else %Q('#{obj}')
25+
end
26+
end
27+
28+
end

lib/generator/exercise_cases.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def skipped
2121
# "#{assert} Isogram.is_isogram?(string)"
2222
# ], 4
2323
# )
24-
def indent_lines(code, depth)
25-
code.join("\n" + ' ' * depth)
24+
def indent_lines(code, depth, separator = "\n")
25+
code.join(separator + ' ' * depth)
2626
end
2727

2828
# used in workload, for example, as

0 commit comments

Comments
 (0)