Repository navigation
list-ops: update to match Kotlin track - #671
Conversation
| @@ -0,0 +1,3 @@ | |||
| ## Hints | |||
There was a problem hiding this comment.
Not sure if we do this in other HINTS files, but I like this!
|
|
||
| private ListOps() { | ||
| // No instances. | ||
| } |
There was a problem hiding this comment.
@FridaTveit would this have provided enough of a starter for you when working on this exercise, do you think? I decided not to add in explicit descriptions of the operations because I think the tests + the type signatures make it possible to deduce the purpose of each operation now?
There was a problem hiding this comment.
Yes, this great! This was exactly what I felt it needed. If users need to take some time to think about what the operations do then that's fine, that should be part of the exercise. I just thought it was a bit of a waste for people to have to spend ages just figuring out what the signatures are. So this is perfect! :)
And the .keep file isn't needed anymore now that we have this file :)
There was a problem hiding this comment.
The keep file was deleted in this PR already, I think?
There was a problem hiding this comment.
Yes, sorry, my mistake :)
| import static junit.framework.TestCase.assertEquals; | ||
| import static junit.framework.TestCase.assertFalse; | ||
| import static junit.framework.TestCase.assertNotNull; | ||
| import static junit.framework.TestCase.assertTrue; |
FridaTveit
left a comment
There was a problem hiding this comment.
Looks great! I really good improvement :) I only have one small question and there's a .keep file we don't need.
Also, do you want to change the estimated difficulty as part of this PR? Or do you think it should still be the same difficulty/do you want to do that in a different PR? :)
|
|
||
| private ListOps() { | ||
| // No instances. | ||
| } |
There was a problem hiding this comment.
Yes, this great! This was exactly what I felt it needed. If users need to take some time to think about what the operations do then that's fine, that should be part of the exercise. I just thought it was a bit of a waste for people to have to spend ages just figuring out what the signatures are. So this is perfect! :)
And the .keep file isn't needed anymore now that we have this file :)
| assertFalse(actual.isEmpty()); | ||
| assertEquals(expected, actual); | ||
| @Test | ||
| public void testFoldLeftWithDirectionDependentOperationOnNonEmptyList() { |
There was a problem hiding this comment.
How is this direction dependent? I understand that the operation in itself is but with these numbers you would get the same answer no matter which direction you traverse the list wouldn't you? Wouldn't it be a better test if that wasn't the case?
There was a problem hiding this comment.
The difference between these two cases is due to some subtleties of how the fold function parameter is typed. In particular, note that it is of type
BiFunction<U, T, U>
for the left fold, and of type
BiFunction<T, U, U>
for the right fold. Since T is the type of the list entries, and U is the type of the accumulated value, this means that if we pass the anonymous function (x, y) -> x / y to both folds, we're actually performing slightly different calculations. See this upstream comment and the ones following for some relevant chatter. So what we're actually doing is the following:
If folding from the left:
Step 0: accumulation = 5
Step 1: accumulation = a / c = 5 / 2 = 2
Step 2: accumulation = a / c = 2 / 5 = 0
If folding from the right:
Step 0: accumulation = 5
Step 1: accumulation = c / a = 5 / 5 = 1
Step 2: accumulation = c / a = 2 / 1 = 2
I updated the function signatures in the test suite to use generic parameter labels x and y rather than accumulation and current to make it clearer that we're using the same anonymous function in both cases. It's up to the user to infer from the (provided) type signature how those parameters should be populated. I update the HINTS file to provide a direct link to the section of the fold Wikipedia page relevant to interpretation of these signatures.
There was a problem hiding this comment.
Okay. So someone solving the exercise definitely can't traverse the list the wrong way and still pass this test?
There was a problem hiding this comment.
I believe that is correct, based on how the anonymous function + method signature combines, yes :)
cada9e9 to
bf3984d
Compare
|
What do you think the new exercise difficulty should be, @FridaTveit? I'm thinking it might not need a huge adjustment since we introduce generics quite late, and this touches generics + functional programming concepts! 😱 |
|
That's true. Maybe change it to 8? |
|
Sounds good; incoming! |
Based on v1.0.0 of the canonical data: https://github.com/exercism/problem-specifications/tree/28a32203b96ebaecac6a6968831bd66718d8ba30/exercises/list-ops Plus modifications that are being discussed in exercism/problem-specifications#826
FridaTveit
left a comment
There was a problem hiding this comment.
Looks great! :) I still have one question about the fold tests but I'm happy for it to be merged :)
| assertFalse(actual.isEmpty()); | ||
| assertEquals(expected, actual); | ||
| @Test | ||
| public void testFoldLeftWithDirectionDependentOperationOnNonEmptyList() { |
Based on v1.0.0 of the canonical data:
https://github.com/exercism/problem-specifications/tree/28a32203b96ebaecac6a6968831bd66718d8ba30/exercises/list-ops
Plus modifications that are being discussed in
exercism/problem-specifications#826
Reviewer Resources:
Track Policies