-
-
Notifications
You must be signed in to change notification settings - Fork 666
Update of testcase generator to latest JSON format #2279
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
Conversation
Dear eklatzerThank you for contributing to the Go track on Exercism! 💙
Dear Reviewer/Maintainer
Automated comment created by PR Commenter 🤖. |
Hey @junedev and @andrerfcsantos, could you please have a look at the implementation and the changes on the test case generator and give me some feedback |
Hey regarding #2056: I have done the following things:
Here is what I faced: when using the code from the
Expected output in
As this test was also implemented in the existing test-cases here the expected value there:
As you can see each value is incremented by 1, compared to the
Please tell me what you expect here |
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.
Thank you so much for this! ❤️
Left some suggestions.
Other than the inline suggestions, two general comments about the PR:
- Right now CI is failing with this error:
tmp/lint/practice/saddle_points/cases_test.go:14: File is not `gofmt`-ed with `-s` (gofmt)
[][]int{[]int{9, 8, 7}, []int{5, 3, 2}, []int{6, 6, 7}},
To fix this, in the root of the repository run gofmt -s -w ./..
.
- The
Gen
function is getting quite big and it's doing a lot. It might be worth separating it into several smaller functions that are more testable. However, I'm fine with this being a separate PR - that shouldn't block this one. Let me know what you think, and if you agree in making this a separate PR, I'll create the issue for it.
I like this better, because it makes the student's solution match the position numbers provided in the example and in the tests. It seems that this exercise originally had the table in the example using 0-based indexes, and when the exercise was introduced in the track, both description and tests were written with that assumption. However, with exercism/problem-specifications#1429 the description and canonical data were updated to use 1-based indexes in problem specs. Then with the change to v3, the exercises' descriptions for the Go track were updated to use the latest version by #1410, but the neither the tests or the exemplar were updated, so it seems a good idea to do it now. |
Hey, is it OK to handle this add the end by adding 1 to the index-based values, or do we want to handle this somewhere else? I removed the old tests, as the ones from |
@eklatzer I'm not sure I understand the question. If you are referring to how to handle this in the example solution then you are free to handle this however you like. The example solution does not have to be a very good solution, it only needs to be a solution that passes the tests for CI purposes. |
Fine :) Are there any changes you want me to add? |
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.
Finished the review. Left some more minor comments/questions.
Two more general points (no need to fix everywhere here):
- When adding context for an error via
fmt.Errorf
or similar, the(%v)
formatting you used is not idiomatic to Go. The old version with the colon is preferred. See for example https://go.dev/blog/go1.13-errors (section "Wrapping errors ..."). If you wonder why this is better, think about what happens when something is wrapped multiple times as it bubbles up the stack. - I can recommend to make error wrapping a habit. At work, I barely ever return an error as is, I usually always wrap before returning it (see https://docs.gitlab.com/ee/development/go_guide/#adding-context for how to do it in way that you get reasonable output). Remember that by default, there are no stack traces attached to the errors so context is very important.
gen/gen.go
Outdated
return fmt.Errorf("[ERROR] failed to marshal test cases with property %s\n%q", property, err) | ||
} | ||
|
||
cache, ok := tests[property] |
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.
I don't understand why the value here is called "cache". Can you think of another name or add a comment to clarify?
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.
I have changed the name and added a comment, but I am not sure if it is better now. What is your opinion?
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.
Still a bit fuzzy but not a blocker.
Two more things I forgot to mention:
|
Co-authored-by: June <12543047+junedev@users.noreply.github.com>
Co-authored-by: June <12543047+junedev@users.noreply.github.com>
Thanks for the feedback🙂 |
We should maybe wait with updating the exercise generators until we have split up the Here a script to get all exercises with a
|
Done: #2300 |
Hey, as already discussed in Slack I have created a draft for the new version of the test case generator. I have also included the code covering #2055 (I have used code from #2276 and adjusted it a bit). Summary of what I have done:
canonical-data.json
and group by the value of the fieldproperty
inclue=false
in thetests.toml
cases_test.go
as the info is not provided in thecanonical-data.json
anymore (#1678)property
(fields that have multiple data-types for one field have to be handled with aninterface{}
and have then to be handled by each specific generator)property.json
as I think this is not needed anymoreTo check if we have forgotten anything I have refactored the following generators:
bowling
: shows how multiple values forproperty
can be handled to generate multiple cases with different structures and also how to handle aninterface{}
directly in the generatordiamond
: no special purpose, but I tried it as I made some changes to this one some days agoforth
: shows how to handle aninterface{}
in the generator (I have also refactored theforth_test.go
a bit as I don't think the info about the groups is really needed here and I also made use oft.Run
and improved the error-messages)NOTE: The use of multiple data types for one field mostly happens values and errors are used like here (
expected
is a struct and a number):