-
-
Notifications
You must be signed in to change notification settings - Fork 655
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
new exercise to encode/decode variable length quantity #322
new exercise to encode/decode variable length quantity #322
Conversation
btw, I'm confused about the failing tests, they are supposed to, that's the whole point of the exercise, isn't it? |
…l be moved to the problem
Your example file needs to provide a working solution. Travis uses it to make sure your tests are valid. Students won't see your example, it's only used as part of the CI process. |
@@ -0,0 +1,15 @@ | |||
package variablelengthquantity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example.go should be a reference solution—something that passes the given test suite. It doesn't get delivered when people fetch
the exercise, it's just used to make sure that the test suite makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Hah. I see that Ian said the same thing below.
Oops sorry, I missed that when I read the guidelines. Just for my own sake, will the users be provided with an empty implementation file? PR update coming |
They will not, unless such a file is explicitly provided. The rule is any file with For example leap/leap.go is given to students, and leap/example.go isn't. As for whether to provide a stub file for this exercise, we discussed in #279 and can revisit, but the general feeling back then was that by the time of reaching the later exercises it isn't really needed anymore. |
PR updated, tests are now passing. I listed this exercise as the last one because I wasn't sure where it would fit, fell free to move it around. I respect your decision in regards to #279 even tho I disagree. At the end of the day it's matter of perspective, type of exercises and what part of the code you'd want students to focus on. It's all good with me. |
|
||
for i, tc := range testCases { | ||
t.Logf("test case %d - %#v\n", i, tc.input) | ||
if o, _ := DecodeVarint(tc.input); o != tc.output { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, given that the second return value is being discarded, it could be anything.
Given that in the example implementation it's the number of bytes consumed, now I want to ponder a few things.
These tests expect a DecodeVarint
that decodes a single number it finds in a buffer.
Should we specify (and therefore test) DecodeVarint
's behavior:
- If there are multiple numbers in the buffer?
[]byte{0x00, 0x00}
- If there is not a complete number in the buffer?
[]byte{0x80, 0x80}
- If the buffer is empty? (which may be a subcase of the "not a complete number in the buffer" case)
Also, as an extension of this funciton that decodes a single varint, should we ask for an implementation of a function that decodes as many numbers as possible from a buffer as well? It would expand the scope of the exercise, though!
I just realized that we never got this merged. @mattetti would you have a moment to look it over and decide if you're happy with it? @petertseng had a few thoughts, but they were more in the "let's ponder this interesting question" than "we need to change this". We could ship it and then see how the exercise does in the wild. What do you think? |
It's been a while indeed! I just went through the exercise and re-read @petertseng's comments. I agree that his suggestions would be nice to add but aren't blockers. @kytrinyx I think it's ready to be merged with one caveat, I'm not sure that the goal of the exercise might not be clear without more context. However since I'm not a exercism user I am not sure what the expectations are or even where to better describe the goal of the exercise and give more context. |
I've reread my comments too. I do believe that "no we don't need to, so no changes are necessary" are valid answers to my questions of the form "should we specify these behaviours? / add this other function?" One thing I would like to make sure on - given that the second return value of
We have this in https://github.com/exercism/x-common/blob/master/exercises/variable-length-quantity/description.md - I know in exercism/problem-specifications#239 there was uncertainty too on whether it was clear. To me, on reading the current description I don't see any specific place where I would say it was unclear, so I think we are good on that front! (But if anyone disagree, that is the place to send the PRs to make it clearer!) |
That's a good point. What do you think @mattetti? |
The API is consistent with the std lib in this case. I would suggest to On Sat, Oct 1, 2016, 14:37 Katrina Owen [email protected] wrote:
|
I hear you! ❤️ If someone has the time to make a PR to this PR that would be awesome! (I added the hacktoberfest label, maybe some friendly gophers can help here) |
@Ngo-The-Trung updated the tests and I merged their PR against my branch but it doesn't seem to be reflected here. The new GH review does seem interesting but I'm on mobile and super confused. Sorry :( |
@mattetti I think it must have been caching, because I see it here. I'm merging this. Thanks @mattetti @Ngo-The-Trung ❤️ |
The PR mattetti#1 caused the new commits to show up in your master branch. But this PR was from your |
Applied using https://github.com/mattetti/xgo/commit/4b6df38d1f44ad1e9501acae4a81ce16ef383953.patch + |
Since it was introduced in #322, the decode function returns the number of bytes decoded. The creator of the exercise mentioned that it was to be consistent with the standard library's API. Go standard library example for returning number of bytes: https://golang.org/pkg/io/#Writer Now, since #674, it is required that the entire input array be decoded, or else it is an error. Now the number of bytes decoded doesn't make much sense to return, since now it is known that it will always be the length of the input. Go standard library example for not returning number of bytes (decoding everything): https://golang.org/pkg/encoding/json/#Unmarshal testVersion -> 4 Closes #683
I'm not sure if that shouldn't move this exercise as a problem. I feel that the problem should be more defined so people understand the goal of the exercise.