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

say: generate tests #885

Merged
merged 3 commits into from
Oct 10, 2017
Merged

Conversation

shaleh
Copy link

@shaleh shaleh commented Oct 5, 2017

This brings the Go track in line with others. Say now returns (string, bool) so it can indicate when a value is out of range.

Part of #605.
Closes #837

@shaleh
Copy link
Author

shaleh commented Oct 5, 2017

I chose to use the ok idiom for the error reporting here. The code can be switched to using error if that is preferred. Ideally this is documented somewhere. Do we know where the right place for that is?

@@ -0,0 +1 @@
.meta/gen
Copy link
Member

Choose a reason for hiding this comment

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

Why ignore .meta/gen here?

@tleen
Copy link
Member

tleen commented Oct 6, 2017

My feeling on it is that unless you have more information to convey than worked/didn't work you use err, otherwise ok.

@shaleh
Copy link
Author

shaleh commented Oct 6, 2017 via email

@shaleh
Copy link
Author

shaleh commented Oct 6, 2017 via email

@tleen
Copy link
Member

tleen commented Oct 6, 2017

Good habit! I have it too! I only noticed because it slipped by me in anagram.

I'm ok with ok it's probably not a bad thing to bring into some exercises since it is a pattern in Go. @robphoenix @leenipper thoughts?

Copy link
Member

@tleen tleen left a comment

Choose a reason for hiding this comment

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

Def remove the gitignore file so we can track gen.

@shaleh
Copy link
Author

shaleh commented Oct 6, 2017 via email

@ferhatelmas ferhatelmas changed the title Say: generate tests say: generate tests Oct 6, 2017
@ferhatelmas
Copy link
Contributor

Def remove the gitignore file so we can track gen.

@tleen I don't understand your above comment because even with gitignore, gen.go is tracked and we don't want to track artifact gen. I think ignore is good since it would prevent errors but place isn't the best. If we want to provide, it should be in the repo level for all exercises.

@tleen
Copy link
Member

tleen commented Oct 6, 2017

Sorry @ferhatelmas I wasn't clear. We wouldn't be adding gen anyway, as you can run the gen without building it. I'm actually ok with it getting added to a commit so we can catch that error. The local .gitignore is a nice safety, but as you said should be done as a global policy, not at the exercise level.

@ferhatelmas
Copy link
Contributor

@tleen Thanks for clarification. We're on the same page then.

Copy link
Contributor

@ferhatelmas ferhatelmas left a comment

Choose a reason for hiding this comment

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

It's good to go when gitignore is removed.

Copy link
Contributor

@leenipper leenipper left a comment

Choose a reason for hiding this comment

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

Suggest one small change in TestSay.

t.Fatalf("FAIL: %s\nExpected error but received: %v", tc.description, actual)
}
} else if !ok {
t.Fatalf("FAIL: %s\nDid not expect an error", tc.description)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest adding:

+               } else if actual != tc.expected {
+                       t.Fatalf("FAIL: %s\nExpected: %v\nActual: %v", tc.description, tc.expected, actual)

@@ -8,7 +8,14 @@ var tens = []string{"ones", "ten", "twenty", "thirty", "forty",
var scale = []string{"thousand", "million", "billion",
"trillion", "quadrillion", "quintillion"}

func Say(n uint64) string {
func Say(n int64) (value string, ok bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm good with ok bool here. The standard library has instances like it.

Copy link
Member

Choose a reason for hiding this comment

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

Does anybody know if/where there is some sort of community accepted definition or guideline as for when to use an err vs an ok?

Copy link
Contributor

Choose a reason for hiding this comment

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

I have not found a straight out "accepted definition". There is discussion. Here is one from 2015: https://groups.google.com/forum/#!topic/golang-nuts/e5qIlnhpgg0
The two points I note are:

  1. when only one possible error condition, a bool is fine.
  2. using an error is more flexible for future updates.

I think for Say, it meets no. 1 (out of range is the !ok case), and doesn't warrant no. 2.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @leenipper that was sort of my take on it too. Good to see I was not alone in it!

Copy link
Author

Choose a reason for hiding this comment

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

@leenipper thanks for catching that. New patch on the way soon.

Sean 'Shaleh' Perry added 2 commits October 9, 2017 08:35
@tleen tleen merged commit 3e89b2c into exercism:nextercism Oct 10, 2017
robphoenix pushed a commit that referenced this pull request Oct 10, 2017
robphoenix pushed a commit to robphoenix/exercism-go that referenced this pull request Oct 10, 2017
robphoenix pushed a commit to robphoenix/exercism-go that referenced this pull request Oct 10, 2017
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.

4 participants