Skip to content

Add transpose test cases #320

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 1 commit into from
Aug 9, 2016

Conversation

ErikSchierboom
Copy link
Member

No description provided.

@petertseng
Copy link
Member

I like what I see for integers.

The exercise description and source specifiy text as well, how do we want to handle that?

There is a PR on xRust that assume text inputs, and the additional implication here is that the rows/columns need not all be equal sizes. Some additional cases to deal with those would probably be appropriate.

@ErikSchierboom
Copy link
Member Author

Good idea, I'll add some string cases too that take into account varying row/column lengths.

@ErikSchierboom
Copy link
Member Author

@petertseng Having read the exercise, it does indeed explicitly mention text. If we would also like to support transposing non-string arrays, I think it makes sense to have a multiline string passed as an array of strings (each line being an array entry). What do you think?

@Insti
Copy link
Contributor

Insti commented Aug 8, 2016

Is it likely that a solution that solves for arrays of numbers will not also solve arrays of strings?
(My dynamically typed language bias may be showing through here.)

@ErikSchierboom
Copy link
Member Author

@Insti Yes, but it is not clear from the exercise text that the string is passed as an array of strings instead of a string with newline characters.

@Insti
Copy link
Contributor

Insti commented Aug 8, 2016

The description:

Write a program that takes input text and outputs it -- transposed.

Would seem to suggest that the input (and output) is text with newlines which would make the arrays in the .json file inappropriate?

Edit to add:

I think it makes sense to have a multiline string passed as an array of strings (each line being an array entry)

Given the input and output are expected to be text, I strongly disagree with this.

@ErikSchierboom
Copy link
Member Author

@petertseng @Insti Maybe we should then only focus on text and not on integers?

@Insti
Copy link
Contributor

Insti commented Aug 8, 2016

Yes, probably.

But it looks like fsharp is the only track that implements this problem?
In which case just change the description to match what you want to do 😃

@ErikSchierboom
Copy link
Member Author

@Insti Well, I was coming around to that :) The only thing that would be modified is that multiple lines are passed as an array of strings.

@Insti
Copy link
Contributor

Insti commented Aug 8, 2016

Opinion:
A problem that involves transforming text into text is more interesting than one that turns an x by y array into a y by x array.
(Even if it's essentially the same thing with added split/join)

@ErikSchierboom
Copy link
Member Author

@Insti Agreed. I'll close this PR.

@ErikSchierboom ErikSchierboom deleted the transpose-json branch August 8, 2016 10:05
@Insti
Copy link
Contributor

Insti commented Aug 8, 2016

A Word square would make an interesting test case.

H E A R T
E M B E R
A B U S E
R E S I N
T R E N D

@Insti
Copy link
Contributor

Insti commented Aug 8, 2016

And Word rectangles (from the same page)

F R A C T U R E
O U T L I N E D
B L O O M I N G
S E P T E T T E

@ErikSchierboom ErikSchierboom restored the transpose-json branch August 8, 2016 10:33
@ErikSchierboom
Copy link
Member Author

@Insti On second thought, maybe I should update the PR with some new, string-based examples?

@ErikSchierboom ErikSchierboom reopened this Aug 8, 2016
@Insti
Copy link
Contributor

Insti commented Aug 8, 2016

@ErikSchierboom I think that's a good idea.

@ErikSchierboom
Copy link
Member Author

@Insti @petertseng I've updated the test cases to work with strings. Better?

"JSON doesn't allow for multi-line strings, so all multi-line input is ",
"presented here as arrays of strings. It's up to the test generator to join the ",
"lines together with line breaks."
],
Copy link
Contributor

Choose a reason for hiding this comment

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

{"multi_line_string":"Multi\nLine\nString\n"}

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it should be: JSON doesn't allow for elegant formatting of multi-line strings, so all multi-line input and output is...

Copy link
Member Author

Choose a reason for hiding this comment

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

That seems like a good wording. I copied the text from the existing JSON data from food-chain by the way.

@Insti
Copy link
Contributor

Insti commented Aug 8, 2016

This new version looks great 👍

It would be good with some simple initial test cases.

A1

A
1

and

ABC
123 

A1
B2
C3

and their inverses.

When doing an exercise, the less output I need to look through to work out what might be wrong the better.

@ErikSchierboom
Copy link
Member Author

Good idea. Will add them.

@ErikSchierboom
Copy link
Member Author

@Insti done!

"ni",
"en",
".e",
"."
Copy link
Member

@petertseng petertseng Aug 9, 2016

Choose a reason for hiding this comment

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

in the original text, the period belongs to the second line, so there should be a space before it in the transposed text

(That would be consistent with what the source https://www.reddit.com/r/dailyprogrammer/comments/4msu2x/challenge_270_easy_transpose_the_input_text says, and the PR exercism/rust#151 )

Copy link
Member Author

Choose a reason for hiding this comment

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

Also fixed in the updated PR.

@Insti
Copy link
Contributor

Insti commented Aug 9, 2016

There doesn't seem to be a test case where the first line is longer than the second line.

@ErikSchierboom ErikSchierboom force-pushed the transpose-json branch 2 times, most recently from f8f3172 to e00effe Compare August 9, 2016 08:45
@ErikSchierboom
Copy link
Member Author

@Insti @petertseng I've updated the incorrect test cases, and added a test case where the first line is longer than the second line.

I've also looked at the xRust PR and it appears their test case also had some problems, where input spaces where stripped in the output.

@petertseng
Copy link
Member

I think everything is in order (I haven't verified with code though).

It might be worth adding to the README a few things, because otherwise the problem seems unspecified.

  • What happens when line are different lengths (pad to the left with spaces, but don't pad to the right)
  • If a column in the input text contains only spaces on its bottom-most rows, should the corresponding output row contain the spaces in its right-most columns?
    • The source says they shouldn't.
    • I can see argument for why it should because that's what's in the input text, and we're just transposing it! And that's what the test cases expect
    • I absolutely do not care what we choose, and we currently chose "keep the spaces", so we can roll with that.

@ErikSchierboom
Copy link
Member Author

@petertseng The README has been updated as suggested. Is it clear enough?


And transposing:

Therefore, transposing this matrix:
Copy link
Member

Choose a reason for hiding this comment

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

remove this line, I think

@petertseng
Copy link
Member

petertseng commented Aug 9, 2016

I like what I see here (with a few small fixes)

👍 from me once the fixes are applied

@ErikSchierboom
Copy link
Member Author

@petertseng I've fixed the remaining issues and I'll merge it. Thanks for the help!

@ErikSchierboom ErikSchierboom merged commit fc028df into exercism:master Aug 9, 2016
@ErikSchierboom ErikSchierboom deleted the transpose-json branch August 9, 2016 19:36
" o n",
" v d",
" e .",
" , "
Copy link
Member

Choose a reason for hiding this comment

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

I think I missed a small thing - no spaces after the comma, right?

(I also haven't checked with code, so I may have missed others, but I least see this)

Copy link
Member

Choose a reason for hiding this comment

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

I'll send the PR. This was the only thing.

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