Skip to content

generators: convert generators to use auto extract #567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 61 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e30946e
add class_name to GeneratorCases
hilary Apr 23, 2017
77cac07
programmatically generate cases
hilary Apr 23, 2017
6134c48
extract CaseValues from TemplateValuesFactory
hilary Apr 24, 2017
982e9b3
separate logic for proc and auto extraction
hilary Apr 25, 2017
263e233
add #proc? to GeneratorCases
hilary Apr 25, 2017
068d1f5
fold Extract into TemplateValuesFactory
hilary Apr 25, 2017
75b81d7
Minor: Remove unnecessary whitespace changes.
Insti Apr 26, 2017
9f6a9e3
Remove redundant test.
Insti Apr 26, 2017
1700748
Inline the GammaCase rather than reading it from a file.
Insti Apr 26, 2017
33e0881
Move case values tests into a single file.
Insti Apr 26, 2017
f088d24
Remove redundant Mocks.
Insti Apr 26, 2017
001e608
Add test coverage for unimplmented extract method.
Insti Apr 26, 2017
012ce13
Eliminte LOAD_PATH modifications.
Insti Apr 26, 2017
9547152
Use fixture data we already have.
Insti Apr 26, 2017
d29bceb
Remove unnecessary inclusion of CaseValues
Insti Apr 26, 2017
8b2ae2a
Extract complex json to fixture file.
Insti Apr 26, 2017
8fb05bf
Remove unnecessary string conversions.
Insti Apr 26, 2017
45511ff
Explicitly load the ProblemCases file we need.
Insti Apr 26, 2017
0b47df3
remove proc support (not needed)
hilary Apr 26, 2017
fcec4ab
remove manual case extraction from clean generators
hilary Apr 23, 2017
6e535a9
update gigasecond tests (was not generatable)
hilary Apr 24, 2017
3c313de
remove instructions re ProblemNameCases from README
hilary Apr 24, 2017
1add0ee
convert pangram to auto extract cases
hilary Apr 24, 2017
465903b
update acronym tests
hilary Apr 24, 2017
ae5a4d1
fix alphametics generator
hilary Apr 24, 2017
423dfc5
convert alphametics to use ExerciseCase
hilary Apr 24, 2017
78d448b
update and convert anagram
hilary Apr 24, 2017
be4c528
convert beer-song
hilary Apr 24, 2017
28c3161
revert unnecessary anagram version bump
hilary Apr 24, 2017
a816e0b
convert anagram workload to four line
hilary Apr 25, 2017
7d6ab33
convert (and fix) two-bucket generator
hilary Apr 25, 2017
3f9d7d3
convert (and fix) bowling generator
hilary Apr 25, 2017
2983e26
convert bracket-push
hilary Apr 25, 2017
372f0b6
convert clock
hilary Apr 25, 2017
0f35d91
convert (and update) connect
hilary Apr 25, 2017
6950d68
convert custom-set
hilary Apr 26, 2017
70d9bce
convert difference-of-squares
hilary Apr 26, 2017
aee153d
convert dominoes
hilary Apr 26, 2017
5c0b3d8
convert hello-world
hilary Apr 26, 2017
2a1e0aa
add indentation helper for multi-line workloads
hilary Apr 26, 2017
0b46dfb
convert isogram
hilary Apr 26, 2017
646e72a
convert (and update) largest-series-product
hilary Apr 26, 2017
4470a07
convert (and update) leap
hilary Apr 26, 2017
d2ae3d6
convert nth-prime
hilary Apr 26, 2017
8e786c9
convert raindrops
hilary Apr 26, 2017
b72a89d
convert rna-transcription
hilary Apr 26, 2017
1f75622
convert roman-numerals
hilary Apr 26, 2017
1765e98
convert sieve
hilary Apr 26, 2017
70954d8
convert transpose
hilary Apr 26, 2017
b6d0b08
convert word-count
hilary Apr 26, 2017
0dff196
convert (and fix) binary
hilary Apr 26, 2017
9fe3565
convert (and fix) say
hilary Apr 26, 2017
01abfc9
convert, update and fix run-length-encoding generator
hilary Apr 26, 2017
2023c78
convert wordy
hilary Apr 26, 2017
195640c
fix wordy tests
hilary Apr 26, 2017
eb993be
convert (and fix) triangle generator
hilary Apr 26, 2017
519163c
convert (and fix) grains generator
hilary Apr 26, 2017
a26d051
removed obsolete grains_cases tests
hilary Apr 26, 2017
a739e6b
convert (and fix) tournament generator
hilary Apr 26, 2017
ba795b3
convert all-your-base
hilary Apr 26, 2017
c56bd33
convert (and fix) queen attack generator
hilary Apr 26, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,39 +157,6 @@ and any setup required. The base class provides a variety of assertion and
helper methods. Beyond that, you can implement any helper methods that you need
as private methods in your derived class. See below for more information about [the intention of workload](#workload-philosophy)

Below this class, implement a small loop that will generate all the test cases by reading the
`canonical-data.json` file, and looping through the test cases.

You will need to adjust the logic to match the structure of the canonical data.

For example, if there is a single top-level key named "cases", then you can loop through
them as follows:

```
ProblemNameCases = proc do |data|
JSON.parse(data)['cases'].map.with_index do |row, i|
ProblemNameCase.new(row.merge('index' => i))
end
end
```

If there are multiple sections, then you will need to loop through the sections, and then
loop through each of the cases in an inner loop:

```
ProblemNameCases = proc do |data|
json = JSON.parse(data)
cases = []
%w(section1 section2 etc).each do |section|
json[section]['cases'].each do |row|
row = row.merge(row.merge('index' => cases.size, 'section' => section))
cases << ProblemNameCase.new(row)
end
end
cases
end
```

Finally, you need to create a text template, `example.tt`, as the bases for the test suite.

Start with the following boilerplate, and adjust as necessary. Remember, however, to strive
Expand Down
2 changes: 1 addition & 1 deletion exercises/acronym/.meta/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2
3
23 changes: 14 additions & 9 deletions exercises/acronym/acronym_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,41 @@
require 'minitest/autorun'
require_relative 'acronym'

# Test data version:
# 5b5e807
# Common test data version: dcfe476
class AcronymTest < Minitest::Test
def test_basic
assert_equal 'PNG', Acronym.abbreviate('Portable Network Graphics')
# skip
assert_equal "PNG", Acronym.abbreviate('Portable Network Graphics')
end

def test_lowercase_words
skip
assert_equal 'ROR', Acronym.abbreviate('Ruby on Rails')
assert_equal "ROR", Acronym.abbreviate('Ruby on Rails')
end

def test_camelcase
skip
assert_equal 'HTML', Acronym.abbreviate('HyperText Markup Language')
assert_equal "HTML", Acronym.abbreviate('HyperText Markup Language')
end

def test_punctuation
skip
assert_equal 'FIFO', Acronym.abbreviate('First In, First Out')
assert_equal "FIFO", Acronym.abbreviate('First In, First Out')
end

def test_all_caps_words
skip
assert_equal 'PHP', Acronym.abbreviate('PHP: Hypertext Preprocessor')
assert_equal "PHP", Acronym.abbreviate('PHP: Hypertext Preprocessor')
end

def test_non_acronym_all_caps_word
skip
assert_equal "GIMP", Acronym.abbreviate('GNU Image Manipulation Program')
end

def test_hyphenated
skip
assert_equal 'CMOS', Acronym.abbreviate('Complementary metal-oxide semiconductor')
assert_equal "CMOS", Acronym.abbreviate('Complementary metal-oxide semiconductor')
end

# Problems in exercism evolve over time, as we find better ways to ask
Expand All @@ -54,6 +59,6 @@ def test_hyphenated

def test_bookkeeping
skip
assert_equal 2, BookKeeping::VERSION
assert_equal 3, BookKeeping::VERSION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the changes here warrant a version bump.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It added a test, hence the version bump.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I missed that

end
end
2 changes: 1 addition & 1 deletion exercises/acronym/example.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module BookKeeping
VERSION = 2
VERSION = 3
end

class Acronym
Expand Down
11 changes: 7 additions & 4 deletions exercises/acronym/example.tt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ require 'minitest/autorun'
require_relative 'acronym'

# Common test data version: <%= abbreviated_commit_hash %>
class AcronymTest < Minitest::Test<% test_cases.each do |test_case| %>
def <%= test_case.name %><% if test_case.skipped? %>
skip<% end %>
assert_equal '<%= test_case.expected %>', <%= test_case.assertion %>
class AcronymTest < Minitest::Test
<% test_cases.each do |test_case| %>
def <%= test_case.name %>
<%= test_case.skipped %>
<%= test_case.workload %>
end

<% end %>
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>

def test_bookkeeping
skip
assert_equal <%= version %>, BookKeeping::VERSION
Expand Down
2 changes: 1 addition & 1 deletion exercises/all-your-base/all_your_base_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'minitest/autorun'
require_relative 'all_your_base'

# Test data version: aa12f2e
# Common test data version: 39de23b
class AllYourBaseTest < Minitest::Test
def test_single_bit_one_to_decimal
# skip
Expand Down
7 changes: 4 additions & 3 deletions exercises/all-your-base/example.tt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ require 'minitest/autorun'
require_relative 'all_your_base'

# Common test data version: <%= abbreviated_commit_hash %>
class AllYourBaseTest < Minitest::Test<% test_cases.each do |test_case| %>
def <%= test_case.test_name %>
class AllYourBaseTest < Minitest::Test
<% test_cases.each do |test_case| %>
def <%= test_case.name %>
<%= test_case.skipped %>
<%= test_case.workload %>
end
<% end %>

<% end %>
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>
def test_bookkeeping
skip
Expand Down
3 changes: 2 additions & 1 deletion exercises/alphametics/alphametics_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'minitest/autorun'
require_relative 'alphametics'

# Test data version: 9dab356
# Common test data version: b9bada8
class AlphameticsTest < Minitest::Test

def test_puzzle_with_three_letters
Expand Down Expand Up @@ -89,6 +89,7 @@ def test_puzzle_with_ten_letters
#
# If you are curious, read more about constants on RubyDoc:
# http://ruby-doc.org/docs/ruby-doc-bundle/UsersGuide/rg/constants.html

def test_bookkeeping
skip
assert_equal 4, BookKeeping::VERSION
Expand Down
3 changes: 2 additions & 1 deletion exercises/alphametics/example.tt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ class AlphameticsTest < Minitest::Test
<% test_cases.each do |test_case| %>

<%= test_case.runtime_comment %>
def <%= test_case.test_name %>
def <%= test_case.name %>
<%= test_case.skipped %>
<%= test_case.workload %>
end
<% end %>

<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>

def test_bookkeeping
skip
assert_equal <%= version %>, BookKeeping::VERSION
Expand Down
55 changes: 35 additions & 20 deletions exercises/anagram/anagram_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,119 +3,134 @@
require 'minitest/autorun'
require_relative 'anagram'

# Test data version:
# 6a886e0
# Common test data version: 196fc1a
class AnagramTest < Minitest::Test
def test_no_matches
# skip
detector = Anagram.new('diaper')
anagrams = detector.match(["hello", "world", "zombies", "pants"])
assert_equal [], anagrams
expected = []
assert_equal expected, anagrams
end

def test_detects_simple_anagram
skip
detector = Anagram.new('ant')
anagrams = detector.match(["tan", "stand", "at"])
assert_equal ["tan"], anagrams
expected = ["tan"]
assert_equal expected, anagrams
end

def test_does_not_detect_false_positives
skip
detector = Anagram.new('galea')
anagrams = detector.match(["eagle"])
assert_equal [], anagrams
expected = []
assert_equal expected, anagrams
end

def test_detects_multiple_anagrams
def test_detects_two_anagrams
skip
detector = Anagram.new('master')
anagrams = detector.match(["stream", "pigeon", "maters"])
assert_equal ["maters", "stream"], anagrams.sort
expected = ["maters", "stream"]
assert_equal expected, anagrams.sort
end

def test_does_not_detect_anagram_subsets
skip
detector = Anagram.new('good')
anagrams = detector.match(["dog", "goody"])
assert_equal [], anagrams
expected = []
assert_equal expected, anagrams
end

def test_detects_anagram
skip
detector = Anagram.new('listen')
anagrams = detector.match(["enlists", "google", "inlets", "banana"])
assert_equal ["inlets"], anagrams
expected = ["inlets"]
assert_equal expected, anagrams
end

def test_detects_multiple_anagrams
def test_detects_three_anagrams
skip
detector = Anagram.new('allergy')
anagrams = detector.match(["gallery", "ballerina", "regally", "clergy", "largely", "leading"])
assert_equal ["gallery", "largely", "regally"], anagrams.sort
expected = ["gallery", "largely", "regally"]
assert_equal expected, anagrams.sort
end

def test_does_not_detect_identical_words
skip
detector = Anagram.new('corn')
anagrams = detector.match(["corn", "dark", "Corn", "rank", "CORN", "cron", "park"])
assert_equal ["cron"], anagrams
expected = ["cron"]
assert_equal expected, anagrams
end

def test_does_not_detect_non_anagrams_with_identical_checksum
skip
detector = Anagram.new('mass')
anagrams = detector.match(["last"])
assert_equal [], anagrams
expected = []
assert_equal expected, anagrams
end

def test_detects_anagrams_case_insensitively
skip
detector = Anagram.new('Orchestra')
anagrams = detector.match(["cashregister", "Carthorse", "radishes"])
assert_equal ["Carthorse"], anagrams
expected = ["Carthorse"]
assert_equal expected, anagrams
end

def test_detects_anagrams_using_case_insensitive_subject
skip
detector = Anagram.new('Orchestra')
anagrams = detector.match(["cashregister", "carthorse", "radishes"])
assert_equal ["carthorse"], anagrams
expected = ["carthorse"]
assert_equal expected, anagrams
end

def test_detects_anagrams_using_case_insensitive_possible_matches
skip
detector = Anagram.new('orchestra')
anagrams = detector.match(["cashregister", "Carthorse", "radishes"])
assert_equal ["Carthorse"], anagrams
expected = ["Carthorse"]
assert_equal expected, anagrams
end

def test_does_not_detect_a_word_as_its_own_anagram
skip
detector = Anagram.new('banana')
anagrams = detector.match(["Banana"])
assert_equal [], anagrams
expected = []
assert_equal expected, anagrams
end

def test_does_not_detect_a_anagram_if_the_original_word_is_repeated
skip
detector = Anagram.new('go')
anagrams = detector.match(["go Go GO"])
assert_equal [], anagrams
expected = []
assert_equal expected, anagrams
end

def test_anagrams_must_use_all_letters_exactly_once
skip
detector = Anagram.new('tapper')
anagrams = detector.match(["patter"])
assert_equal [], anagrams
expected = []
assert_equal expected, anagrams
end

def test_capital_word_is_not_own_anagram
skip
detector = Anagram.new('BANANA')
anagrams = detector.match(["Banana"])
assert_equal [], anagrams
expected = []
assert_equal expected, anagrams
end

# Problems in exercism evolve over time, as we find better ways to ask
Expand Down
2 changes: 1 addition & 1 deletion exercises/anagram/example.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module BookKeeping
VERSION=2
VERSION = 2
end

class Anagram
Expand Down
7 changes: 5 additions & 2 deletions exercises/anagram/example.tt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ require 'minitest/autorun'
require_relative 'anagram'

# Common test data version: <%= abbreviated_commit_hash %>
class AnagramTest < Minitest::Test<% test_cases.each do |test_case| %>
def <%= test_case.test_name %>
class AnagramTest < Minitest::Test
<% test_cases.each do |test_case| %>
def <%= test_case.name %>
<%= test_case.skipped %>
<%= test_case.workload %>
end

<% end %>
<%= IO.read(XRUBY_LIB + '/bookkeeping.md') %>

def test_bookkeeping
skip
assert_equal <%= version %>, BookKeeping::VERSION
Expand Down
1 change: 1 addition & 0 deletions exercises/beer-song/beer_song_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def test_all_verses
TEXT
assert_equal expected, BeerSong.new.verses(99, 0)
end

# Problems in exercism evolve over time, as we find better ways to ask
# questions.
# The version number refers to the version of the problem you solved,
Expand Down
Loading