Skip to content

sum-of-multiples: added generator#658

Merged
kotp merged 1 commit intoexercism:masterfrom
ajwann:add-generator-for-sum-of-multiples
Jun 7, 2017
Merged

sum-of-multiples: added generator#658
kotp merged 1 commit intoexercism:masterfrom
ajwann:add-generator-for-sum-of-multiples

Conversation

@ajwann
Copy link
Copy Markdown
Contributor

@ajwann ajwann commented May 25, 2017

references #396


def test_multiples_of_43_or_47_up_to_10000
skip
assert_equal 2203160, SumOfMultiples.new(43, 47).to(10000)
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.

It would be good to use number underscoring with big numbers.

class SumOfMultiplesCase < Generator::ExerciseCase
def workload
indent_lines(["assert_equal #{expected}, SumOfMultiples.new" \
"(#{factors.join(', ')}).to(#{limit})"] , 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.

  1. I like to try really hard to avoid line continuations like this.
  2. Did you know ExerciseCase has an assert_equal helper method?

Copy link
Copy Markdown
Contributor Author

@ajwann ajwann May 30, 2017

Choose a reason for hiding this comment

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

I took a look at the assert_equal helper method, but it's calling inspect on the underscored value (which is a string), and then interpolating that into the assertion. This results in the assertions looking like: assert_equal "1_000", ..., when what we want is to assert two numbers.

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.

Hmm interesting. Thanks.

The whole assertion helper thing is quite new and has many unexplored edge cases.

Creating an issue about this might be a good idea.

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

@Insti
Copy link
Copy Markdown
Contributor

Insti commented May 26, 2017

Nice 👍

@ajwann ajwann force-pushed the add-generator-for-sum-of-multiples branch from b6f9d57 to 6b972a2 Compare May 30, 2017 23:32
@ajwann
Copy link
Copy Markdown
Contributor Author

ajwann commented May 30, 2017

@Insti I was able to add underscoring at the cost of using the assert_equal helper. See my comment above for more details. I'm happy to tweak the string concatenation in my workload method to make it avoid the line continuation if you'd like.

@Insti
Copy link
Copy Markdown
Contributor

Insti commented May 31, 2017

Thanks @ajwann The other changes look good.

I'm happy to tweak the string concatenation in my workload method to make it avoid the line continuation if you'd like.

This would be super 👍

Copy link
Copy Markdown
Member

@kotp kotp left a comment

Choose a reason for hiding this comment

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

Looks good, glad this is going to be generated, but not positive about the method name change.

end

def to(limit)
def take(limit)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What inspired the method name change?

Take a limit is a different idea potentially than to a limit.

The "to" implies an exclusive limit, while take suggests an inclusive limit. An example of this in English is "go to the wall" which implies do not go all the way into the wall, or on the wall, just approach it as close as you can. The Readme is clear that we are to exclude the limit.

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.

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.

Although I had forgotten that the limit was excluded, so the name change may be inappropriate.

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.

take is also not good since we're not actually taking an array, we just want the sum.

I think I've convinced myself that the method name change was a bad idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Haha sounds good. I'll add the line break and take out the new method name. 😂

@ajwann ajwann force-pushed the add-generator-for-sum-of-multiples branch from 6b972a2 to 3568975 Compare June 5, 2017 23:13
@ajwann
Copy link
Copy Markdown
Contributor Author

ajwann commented Jun 5, 2017

@Insti @kotp, I think we are good to go here. I renamed take back to to and got rid of the line continuation.

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)

Copy link
Copy Markdown
Contributor

@Insti Insti left a comment

Choose a reason for hiding this comment

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

Looks good. 👍
Sorry about the renaming confusion, that was my fault. 😊

@Insti Insti added ready and removed in progress labels Jun 7, 2017
@kotp kotp merged commit 65365c1 into exercism:master Jun 7, 2017
@kotp
Copy link
Copy Markdown
Member

kotp commented Jun 7, 2017

Bringing it in, other than the mentioned code by @Insti it looks good to me. We can change that up if it ends up being an irritant. I can see it being that way, on the next round. I can also see the underscore name changing on the same line at some point to snake_case instead, as I find that name a little bit meh, too. Just not irritated enough to change it.

@kotp
Copy link
Copy Markdown
Member

kotp commented Jun 7, 2017

Thank you @Insti and @ajwann good job as always!

@Insti Insti removed the ready label Jun 8, 2017
@Insti Insti mentioned this pull request Oct 1, 2017
94 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants