Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions exercises/sum-of-multiples/.meta/.version
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)
Copy link
Copy Markdown
Contributor

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_expected you have only 2/3 of a valid assert_equal call.
value is good.
constructing the string at the end is ok due to your variable naming, but confusing because assert_expected looks like a minitest method but it isn't one.

I would have done this:

result = "SumOfMultiples.new(#{factors.join(', ')}).to(#{limit})"
indent_lines(["assert_equal #{expected.underscore}, #{result}"], 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)
Expand Down
63 changes: 51 additions & 12 deletions exercises/sum-of-multiples/sum_of_multiples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Contributor

@Insti Insti May 26, 2017

Choose a reason for hiding this comment

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

Probably unrelated to generator, but would it be interesting to allow SumOfMultiples to return something more Enumerable?
SumOfMultiples.new(3,5).take(1)
cc: @kotp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm really liking the idea of changing the method name from to to take

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