Skip to content

Add transpose#466

Merged
kotp merged 1 commit intoexercism:masterfrom
gchan:transpose
Oct 24, 2016
Merged

Add transpose#466
kotp merged 1 commit intoexercism:masterfrom
gchan:transpose

Conversation

@gchan
Copy link
Copy Markdown
Contributor

@gchan gchan commented Oct 19, 2016

Test generator for the transpose exercise and example solution.

@Insti
Copy link
Copy Markdown
Contributor

Insti commented Oct 19, 2016

Super, Thanks ❤️
I'll have a look at this later today.

Comment thread config.json
"isogram"
"isogram",
"transpose"
],
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.

Added to the end, great, that is the right place to put new problems. 👍

Comment thread exercises/transpose/example.tt Outdated
<%= test_case.skipped %>
expect = <%= test_case.expect %>
actual = <%= test_case.work_load %>
assert_equal expect, actual
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 really like the 3 line format you're using here.
I'd call it expected but expect is ok too.

Comment thread lib/transpose_cases.rb Outdated
end

def work_load
"Transpose.transpose(#{input_text.dump})"
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.

Nice use of dump to handle escaping.

@Insti
Copy link
Copy Markdown
Contributor

Insti commented Oct 19, 2016

This looks good ❤️

🤔 I wonder if there's some way of making the tests better show the transposed results.

Edit: I guess the test failure messages show it a bit better so maybe we don't need to do anything different in the test_cases file.

@Insti Insti added the ready label Oct 19, 2016
@gchan gchan force-pushed the transpose branch 2 times, most recently from 657d1d1 to ff05173 Compare October 20, 2016 07:04
@gchan
Copy link
Copy Markdown
Contributor Author

gchan commented Oct 20, 2016

Thanks @Insti, I've renamed the variable expect to expected

Could potentially use HEREDOC or string concatenation with \ to make the transposed results look better in the test file. WDYT?

@gchan gchan force-pushed the transpose branch 3 times, most recently from c47a989 to e9ec73b Compare October 20, 2016 07:15
@Insti
Copy link
Copy Markdown
Contributor

Insti commented Oct 20, 2016

Could potentially use HEREDOC or string concatenation with \ to make the transposed results look better in the test file. WDYT?

If you want to try it and see how it looks that would be good.

You could add other temporary files to the PR called test_cases_with_heredoc.rb or something, so we can compare the different versions. Then when we've decided which is best we can delete the redundant ones before merging.

Another thing we could do is add a comment to the test_cases.rb file asking people to submit an issue if they have an idea for a better way to display it.

@gchan
Copy link
Copy Markdown
Contributor Author

gchan commented Oct 20, 2016

Added files for a heredoc version for test generation. 😄

@Insti
Copy link
Copy Markdown
Contributor

Insti commented Oct 20, 2016

Ok, Thanks for doing that ❤️

The initial version is my preferred one.
I really don't like how the heredoc test cases end up looking.
(But leave them in for now to give others a chance to look at them as well.)

@Insti Insti added in progress and removed ready labels Oct 20, 2016
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.

Heredoc indentation is a good thing, and not hard to implement. I think we will need to, as I think we are still using Ruby 2.2.

input = <<-INPUT
ABC
123
INPUT
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.

With a tilde ~ in front of the Heredoc delimiter, you can present these heredocs with the proper indentation, and they will end up looking good here and clean in the generated files. Including indentation in side the text. This does require Ruby 2.3 though, but it is not a hard thing to write. Facets gem has this functionality for a fairly long time (I wrote one in 2008, unsure if Facets got my version).

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.

The tilde for heredocs in Ruby 2.3 is nice feature. Thanks for the tip!

@kotp
Copy link
Copy Markdown
Member

kotp commented Oct 23, 2016

@Insti You still prefer the first version, or did the heredocs change do it for you?

@Insti
Copy link
Copy Markdown
Contributor

Insti commented Oct 23, 2016

The indented heredocs are much nicer.
I think we should just use the heredoc version.

Comment thread lib/transpose_cases.rb Outdated
[
"<<-EXPECTED.gsub(/^ {6}/, '')",
indent_lines(expected),
indent_line('EXPECTED')
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'd extract an indented_heredoc method.

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.

Replace indent_line('EXPECTED') with `indented_heredoc('EXPECTED')?

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.

No. replace

"<<-EXPECTED.gsub(/^ {6}/, '')",
indent_lines(expected),
indent_line('EXPECTED')

with
indented_heredoc(expected)

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.

Create a helper method to indent those things, all of them are by 6, that is the argument to the method.

<<-EXPECTED.trim_to(6)

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.

Please see latest changes. Not sure if there is a trim_to method for Ruby String?

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.

There could be. :) You can make one. That is what I was saying. The name would probably be left_trim though to be clear.

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.

For this to work I will have to monkey patch the String class with a left_trim method in the generated tests?

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.

Refinements may be an approach as well.

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.

Consider that this is not critical. So this should be something to think about, and play with. The duplication here should not stop this PR.

@kotp kotp merged commit 19f3de5 into exercism:master Oct 24, 2016
@Insti
Copy link
Copy Markdown
Contributor

Insti commented Oct 24, 2016

Thanks for all your work on this @gchan ❤️

@gchan
Copy link
Copy Markdown
Contributor Author

gchan commented Oct 24, 2016

No problem. Thanks for the feedback. I learnt a few things along the way

@Insti Insti removed the in progress label Oct 24, 2016
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