luhn: update test files#479
Conversation
|
I realise exercism/problem-specifications#522 and exercism/problem-specifications#523 are still open and could well affect this PR, so our track should leave this unmerged until they are resolved, and any relevant updates can be made to these commits. |
There was a problem hiding this comment.
Sure, we can look at this again when the two x-common issues are done.
The circumstance in which we would merge it now:
- We predict that neither x-common issue will require a change to the generator or example solution; we just run the generator again.
- We think there is a big advantage in getting the tests in this PR out to the students out -- they offer something the current tests don't (currently the distinction is pretty small, but you could convince me otherwise)
Alternatively if you just want to pull the "move TestTestVersion" into a separate PR we can get that merged now; it doesn't depend on having a generator.
Also, probably good to prefix the "move TestTestVersion" commit with "luhn:"
a92205c to
e9e1fec
Compare
|
separated into 2 PRs (#480) |
e9e1fec to
2526581
Compare
|
I've updated this to reflect the merged changes form exercism/problem-specifications#522, the |
| d := make([]int, 0, len(id)) | ||
|
|
||
| for _, r := range id { | ||
| if r != ' ' && (r < '0' || r > '9') { |
There was a problem hiding this comment.
personally, I would strive to avoid the repetition of the '0' and '9', by saying continue if r == ' ', then the remaining cases are if/else of each other. Assuming I didn't get my logic wrong. Does it make sense?
There was a problem hiding this comment.
that makes better sense, yes
| return d | ||
|
|
||
| last := len(d) - 1 | ||
| return (check(d[:last])+d[last])%10 == 0 |
There was a problem hiding this comment.
I'm assuming check returns the sum? Would anything go wrong if we just used check(d) % 10 == 0?
E: Oh never mind, this is a same line as above, just moved. I guess we don't need to change it, though if it's going to show up in git diff as a diff anyway, maybe we could consider
2526581 to
53771cd
Compare
|
updated to take into account @petertseng comments. The |
| } | ||
| if r >= '0' && r <= '9' { | ||
| d = append(d, int(r-'0')) | ||
| } else { |
There was a problem hiding this comment.
this makes me realize there are some alternatives for how to structure this. They all have some advantage or disadvantage, so you can pick one you like after trying out:
-
Don't bother having
if r == ' ' { continue }above. Instead just haveelse if r != ' ' { return false }here. Pro: Fewer clauses. Cons: May be a little harder to understand in what cases it does neither. -
Invert the checks, say
if r < '0' || r > '9' { return false }above. Pro: Now thed = appendcan be unindented. Con: Have to read through two conditions before getting to the "actual" loop body (the case that causes something interesting to happen) -
Leave as-is. Pro: Smaller diff against current code. Con: typical-case loop body sandwiched between two other cases.
There was a problem hiding this comment.
I chose door no. 2 👍
53771cd to
1846d05
Compare
1846d05 to
0ea6cd8
Compare
|
I think we can merge this now without waiting on exercism/problem-specifications#523 to be resolved, we can update the exercise when that happens. |
Add an example_gen.go testCases generator to generate the testCases from the x-common canonical data. Generate the new testCases data and update the example to pass the new test data. Bump the testVersion to 2.
0ea6cd8 to
c339882
Compare
There was a problem hiding this comment.
I find it likely that exercism/problem-specifications#523 will not change the structure of the JSON file, so we can simply rerun the generator at that time, and not wait.
Of course, there is a new JSON schema, but when that gets applied it might make our lives easier since supposedly that means each exercise's JSON file will have in common, which means we can write less exercise-specific code. We will see if that bears fruit!
|
👍 |
Add an example_gen.go testCases generator to generate the testCases from
the x-common canonical data. Generate the new testCases data and update
the example to pass the new test data. Bump the testVersion to 2.