Skip to content
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

custom-set: update generator #622

Merged
merged 2 commits into from
Apr 23, 2017

Conversation

leenipper
Copy link
Contributor

For issue #604.

Use .Header in generator template.
Align template with latest canonical-data.json.
Use a OneCase struct type to contain the whole
set of possible json objects for the various
test groups.
Add istrSlice as conversion helper for .Expected.

@leenipper
Copy link
Contributor Author

This generator also uses TestGroups and GroupComment, like the clock exercise generator, and also introduces a PropertyMatch function which may also be reusable. I thought it best to hold any re-factor of clock and custom-set generator with a change to gen/gen.go until later. Handle with separate issue perhaps.

Copy link
Contributor

@robphoenix robphoenix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @leenipper , but I'd appreciate another reviewer, and have a couple of queries.

Expected []int
func (c OneCase) PropertyMatch(property string) bool { return c.Property == property }

func (groups TestGroups) GroupComment(property string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should've done this in the Clock PR (#620), but I'm not sure I understand this GroupComment. I'm not questioning it, I'd just benefit from an explanation of what it's doing and why you've added it @leenipper. And I think it would be good to move any explanation into a doc comment as well, for future reference and future contributors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

{{with .J.Groups}}
// {{ .GroupComment "subset"}}
{{end}} var subsetCases = []binBoolCase{ {{range .J.Groups}} {{range .Cases}}
{{if .PropertyMatch "subset"}} { // {{.Description}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to pass "subset"/"disjoint"/"equal" etc. to the template so they can be nested as they currently are?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My attempts to do exactly that have not met with success yet. I have certainly tried to do it, since there is a nice pattern there. I will study it more and see.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed you had 😄 I'll have a look too if I get time. As you say there is a nice pattern there.

@robphoenix
Copy link
Contributor

see #629

// it is used in order to pass multiple parameters in a template call.
func dict(values ...interface{}) (map[string]interface{}, error) {
if len(values)%2 != 0 {
return nil, errors.New("invalid dict call")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth having a more explicit error message? invalid dict call: odd number of values given or somesuch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid dict call: odd number of values given

That is better. Even if only for readers of the code.

// GroupComment looks in each of the test case groups to find the
// group for which every test case has the .Property matching given property;
// it returns the .Description field for the matching property group,
// or a 'Note: ...' if no test group consistently matches given property.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{{template "eleOp" dict "PropertyType" "add" "Groups" .J.Groups}}
{{template "binaryOp" dict "PropertyType" "intersection" "Groups" .J.Groups}}
{{template "binaryOp" dict "PropertyType" "difference" "Groups" .J.Groups}}
{{template "binaryOp" dict "PropertyType" "union" "Groups" .J.Groups}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You found a way! 🎉 You must be pleased with this! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Others discovered this solution prior; some googling helped me find it. Looks odd at first, but solves the problem well.

@robphoenix
Copy link
Contributor

robphoenix commented Apr 21, 2017

LGTM 👍 though again I'd appreciate a second reviewer, @petertseng @tleen @ferhatelmas

@leenipper
Copy link
Contributor Author

leenipper commented Apr 22, 2017

Should this series be squashed and force pushed again, using "For issue #629" in commit message ?

Update: I'll go ahead and do this.

For issue exercism#629.

Use .Header in generator template.
Align template with latest canonical-data.json.
Use a OneCase struct type to contain the whole
set of possible json objects for the various
test groups.
Add istrSlice as conversion helper for .Expected.

Rework each define & template call to also generate
the var for the test cases. Use .GroupComment helper function
to output the description for the test case group.
Use dict helper function to pass multiple parameters to a template.

Update test program to change hasCases => containsCases,
and eqCases => equalCases; the new templates
output each test case array var from within the template and simply
prepend the property to "Cases" for the variable name.
@leenipper leenipper force-pushed the custom-set-update-generator branch from a905e1c to 7aa9e52 Compare April 22, 2017 16:06
}
Property string
Set []int // "empty"/"contains"/"add" cases
Set1 []int // "empty"/"contains"/"add" cases
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the cases for Set1 should be the same as for Set2, not Set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, you are correct.

Set1/Set2 apply to same test case groups.
@leenipper leenipper merged commit 81b2eaf into exercism:master Apr 23, 2017
@leenipper leenipper deleted the custom-set-update-generator branch April 23, 2017 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants