-
-
Notifications
You must be signed in to change notification settings - Fork 531
sum-of-multiples: added generator #658
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| require 'generator/exercise_case' | ||
|
|
||
| class SumOfMultiplesCase < Generator::ExerciseCase | ||
| using Generator::Underscore | ||
|
|
||
| def workload | ||
| assert_expected = "assert_equal #{expected.underscore}" | ||
| value = "SumOfMultiples.new(#{factors.join(', ')}).to(#{limit})" | ||
| indent_lines(["#{assert_expected}, #{value}"], 4) | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| module BookKeeping | ||
| VERSION = 1 | ||
| end | ||
|
|
||
| class SumOfMultiples | ||
| attr_reader :multiples | ||
| def initialize(*multiples) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,48 +2,87 @@ | |
| require 'minitest/autorun' | ||
| require_relative 'sum_of_multiples' | ||
|
|
||
| class SumTest < Minitest::Test | ||
| def test_sum_to_1 | ||
| # Common test data version: 1.0.0 72b1496 | ||
| class SumOfMultiplesTest < Minitest::Test | ||
| def test_multiples_of_3_or_5_up_to_1 | ||
| # skip | ||
| assert_equal 0, SumOfMultiples.new(3, 5).to(1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably unrelated to generator, but would it be interesting to allow
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm really liking the idea of changing the method name from |
||
| end | ||
|
|
||
| def test_sum_to_3 | ||
| def test_multiples_of_3_or_5_up_to_4 | ||
| skip | ||
| assert_equal 3, SumOfMultiples.new(3, 5).to(4) | ||
| end | ||
|
|
||
| def test_sum_to_10 | ||
| def test_multiples_of_3_or_5_up_to_10 | ||
| skip | ||
| assert_equal 23, SumOfMultiples.new(3, 5).to(10) | ||
| end | ||
|
|
||
| def test_sum_to_100 | ||
| def test_multiples_of_3_or_5_up_to_100 | ||
| skip | ||
| assert_equal 2_318, SumOfMultiples.new(3, 5).to(100) | ||
| end | ||
|
|
||
| def test_sum_to_1000 | ||
| def test_multiples_of_3_or_5_up_to_1000 | ||
| skip | ||
| assert_equal 233_168, SumOfMultiples.new(3, 5).to(1000) | ||
| end | ||
|
|
||
| def test_configurable_7_13_17_to_20 | ||
| def test_multiples_of_7_13_or_17_up_to_20 | ||
| skip | ||
| assert_equal 51, SumOfMultiples.new(7, 13, 17).to(20) | ||
| end | ||
|
|
||
| def test_configurable_4_6_to_15 | ||
| def test_multiples_of_4_or_6_up_to_15 | ||
| skip | ||
| assert_equal 30, SumOfMultiples.new(4, 6).to(15) | ||
| end | ||
|
|
||
| def test_configurable_5_6_8_to_150 | ||
| def test_multiples_of_5_6_or_8_up_to_150 | ||
| skip | ||
| assert_equal 4419, SumOfMultiples.new(5, 6, 8).to(150) | ||
| assert_equal 4_419, SumOfMultiples.new(5, 6, 8).to(150) | ||
| end | ||
|
|
||
| def test_configurable_43_47_to_10000 | ||
| def test_multiples_of_5_or_25_up_to_51 | ||
| skip | ||
| assert_equal 2_203_160, SumOfMultiples.new(43, 47).to(10_000) | ||
| assert_equal 275, SumOfMultiples.new(5, 25).to(51) | ||
| end | ||
|
|
||
| def test_multiples_of_43_or_47_up_to_10000 | ||
| skip | ||
| assert_equal 2_203_160, SumOfMultiples.new(43, 47).to(10000) | ||
| end | ||
|
|
||
| def test_multiples_of_1_up_to_100 | ||
| skip | ||
| assert_equal 4_950, SumOfMultiples.new(1).to(100) | ||
| end | ||
|
|
||
| def test_multiples_of_an_empty_list_up_to_10000 | ||
| skip | ||
| assert_equal 0, SumOfMultiples.new().to(10000) | ||
| 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, | ||
| # not your solution. | ||
| # | ||
| # Define a constant named VERSION inside of the top level BookKeeping | ||
| # module, which may be placed near the end of your file. | ||
| # | ||
| # In your file, it will look like this: | ||
| # | ||
| # module BookKeeping | ||
| # VERSION = 1 # Where the version number matches the one in the test. | ||
| # end | ||
| # | ||
| # 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 1, BookKeeping::VERSION | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feedback rather than a change request:
The grouping here is logically confusing as in
assert_expectedyou have only 2/3 of a validassert_equalcall.valueis good.constructing the string at the end is ok due to your variable naming, but confusing because
assert_expectedlooks like a minitest method but it isn't one.I would have done this: