Repository navigation
dibs: I will implement exercise Matrix - #244
Conversation
|
Go Frida, go! |
94352d5 to
3a6995d
Compare
|
Hey @FridaTveit, would you mind connecting with me over email (on my GitHub profile)? I have an Exercism-related question for you. |
|
I'm curious to see what you choose to do with the problem interface here, @FridaTveit - I have pondered this puzzle a little in the past! |
|
You've pondered the puzzle of this problem's protocol? (sorry, couldn't help myself... carry on) |
|
Hah, indeed! In preparation for pontification! |
|
I added a commit with the implementation a while ago but I rebased it on top of master instead of merging it, is that a problem? |
|
Ah, no, that's perfectly fine, I had just missed it! I normally update the PR title to |
|
Ah, okay :) |
|
Hey @stkent I'm assuming that you're reviewing this PR; that your intent? |
|
Sure, I'm happy to; probably won't get to it for a couple days though, so if you want to jump in, that's fine by me. |
| String[] columnValues = rows[i].split(" "); | ||
| matrix[i] = new int[columnValues.length]; | ||
| for (int j = 0; j < columnValues.length; j++) { | ||
| matrix[i][j] = Integer.valueOf(columnValues[j]); |
There was a problem hiding this comment.
Minor detail, but it's probably ok to use Integer.parseInt here instead, which avoid extra boxing/unboxing. See e.g. this SO post for some interesting discussion. Not going to hold the PR for this change alone, just noting for interest :)
There was a problem hiding this comment.
Okay, will change it! :)
| String[] rows = matrixAsString.split("\\n"); | ||
| matrix = new int[rows.length][]; | ||
| for (int i = 0; i < rows.length; i++) { | ||
| String[] columnValues = rows[i].split(" "); |
There was a problem hiding this comment.
Another FYI, not a required change: note that there are some "gotchas" when using String.split with a regex. Here's a nice breakdown. If this was high-performance code, you'd probably want to compile the Pattern ahead of time, and split using that instead. I only learned about this a couple months back.
There was a problem hiding this comment.
Thanks, good to know! :)
| return Arrays.asList(new Object[][]{ | ||
| {"0", new int[] {0}}, | ||
| {"0 1", new int[] {0, 1}}, | ||
| {"0\\n1", new int[] {0}}, |
There was a problem hiding this comment.
Do these strings all need to include the escaped newline? Everything seemed to work ok for me if I replaced all occurrences of \\n with a simple \n? On a related note, would that change make the matrixAsString.replaceAll("\\\\n", "\n") lines removable too?
There was a problem hiding this comment.
Ohh... is this for formatting the parametrized test output? If so, that's a tricky balance; I fear adding then adjusting the newlines in this way might cause implementors some confusion.
There was a problem hiding this comment.
Yes, it is for formatting the test output and I was unsure about it. I agree that adjusting the newlines looks confusing when you look at the code. So having the test output look a bit less nice is probably the better option. I'll change it :)
| {"0 1", new int[] {0}}, | ||
| {"0\\n1", new int[] {0, 1}}, | ||
| {"0 1\\n2 3", new int[] {0, 2}}, | ||
| {"0 1 2\\n3 4 5\\n6 7 8", new int[] {0, 3, 6}} |
There was a problem hiding this comment.
I wonder if it might be possible to format the matrices here in a more intuitive way? Something like the following (last row example):
@Parameterized.Parameters(name = "{index}: checking first row of matrix constructed with string \"{0}\".")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"0", new int[] {0}},
{"0 1", new int[] {0, 1}},
{"0\n1", new int[] {0}},
{"0 1\n2 3", new int[] {0, 1}},
{ "0 1 2\n"
+ "3 4 5\n"
+ "6 7 8", new int[] {0, 1, 2}}
});
}I find it a little easier to draw the connection between the input and the expected output with that formatting, but others might disagree...?
There was a problem hiding this comment.
Sure, that looks good, I'll change it :)
| this.firstColumn = firstColumn; | ||
| } | ||
|
|
||
| @Ignore |
There was a problem hiding this comment.
I think these @Ignores could also be applied so the inner classes themselves instead of the nested @Test methods, which could make them a little easier to spot? e.g.
@Ignore
@RunWith(Parameterized.class)
public static class GetLastRowTest {As before, though, it might just be me that finds the top-level annotation easier to see!
There was a problem hiding this comment.
Sure, that makes sense, I'll change it :)
| @Ignore | ||
| @Test | ||
| public void getLastColumnTest() { | ||
| assertArrayEquals(matrix.getColumn(matrix.getColumnsCount() - 1), lastColumn); |
There was a problem hiding this comment.
JUnit assertions typically request the expected value before the actual value, so we should reverse the parameter ordering of all of these calls to assertArrayEquals - otherwise our failure messages will be backwards and potentially confusing!
There was a problem hiding this comment.
Thanks, will change it! :)
|
@FridaTveit some comments in; mostly musing out loud 😄 . Let me know what you prefer in the cases where I suggested alternatives! |
…gnore in MatrixExercise. Changed Integer.valueOf to Integer.parseInt in Matrix. Changed String.split to using Pattern in Matrix.
|
|
||
| @Test | ||
| public void getLastRowTest() { | ||
| assertArrayEquals(lastRow, matrix.getRow(matrix.getRowsCount() - 1)); |
There was a problem hiding this comment.
Since this test uses getRowsCount to identify the final row of the matrix, I wonder if we should move the test classes CountColumnsTest and CountRowsTest to the very beginning of the test suite? Otherwise those test classes are effectively redundant, as the implementor will already have had to build working implementations of getRowsCount and getColumnsCount to pass earlier tests (like this one).
There was a problem hiding this comment.
True, will move them! :)
|
@FridaTveit thanks, changes look great! I added one more question that I didn't spot the first time around - let me know what you would like to do with that. Once that's been discussed and/or resolved, let's get this merged! |
|
(Small merge with master also needed now :) |
…that they will be run first as other tests rely on them.
|
I took care of those config conflicts using the new inline GitHub merge tool. It worked well! Merging on successful build 🏆 |
No description provided.