-
-
Notifications
You must be signed in to change notification settings - Fork 658
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
[WIP] say: update tests #867
Conversation
Changed documentation to no longer suggest tests with negative numbers and clarify necessary error handling.
@MatForsberg I've changed the base branch from |
What do i need to do to get this accepted? |
Hi Mat, I'm really sorry, these past few weeks have been a bit crazy. I've
just not had time to catch up on this. I will make the effort to properly
review this early next week. Again, sorry for the delay.
On Fri, 29 Sep 2017 at 17:54, Mat Forsberg ***@***.***> wrote:
What do i need to do to get this accepted?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#867 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AI1BRIbnjMr6kVfcmrDtxBF5dsp3q4bwks5snSC6gaJpZM4PeY9v>
.
|
exercises/say/example.go
Outdated
func Say(n uint64) string { | ||
func Say(n uint64) (string, error) { | ||
if n >= 1000000000000 { | ||
return "", &errorString{"Value out of range."} |
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.
@MatForsberg I'm curious about why introduce a new error type instead of using errors.New('value out of range')
? Your new type is not carrying extra data. Also I believe that the string should be in lower case entirely. You can get more information in here:
https://github.com/golang/go/wiki/Errors
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. I have made the suggested changes. I did things that way because I am new to go and that is how i learned to do errors.
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.
Good eye @cored thanks!
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.
Thanks @cored 👍
Some scales where not being used because the instructions of the project specify the number given will be less than one trillion. Changed error handling to use errors library and mad error text all lower case.
Same here, been swamped a bit. I set aside some gotrack time this weekend and this is top on the list! |
@MatForsberg this is a lot like #870 in regards to editing the README.md directly. Take a look at my comment for that PR. Because the README is autogenerated now we actually want to make these modifications in a So I think what we should to do here is:
Whew! Seems like a lot but once you get how the configlet is generating the README files it all makes sense. It is trying to balance the common information from the It is well thought out I promise! 😅 |
There is a fix in the pipeline for this: exercism/configlet#84 |
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.
Thanks for this @MatForsberg and sorry you've had to wait so long for an appropriate response.
I think it's best if we change the exercise to take a signed int64
rather than the uint64
it currently does. This would mean we wouldn't need to diverge from the description & canonical-data in the problem-specifications repo.
This means the README wouldn't need any changes. The test cases would need to be updated to reflect those that are in the problem-specifications repo: https://github.com/exercism/problem-specifications/blob/master/exercises/say/canonical-data.json and the example to be updated to work with the new test cases.
How does that sound to you?
|
||
func Say(n uint64) string { | ||
func Say(n uint64) (string, error) { |
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 think this should be changed to a signed int64
, so we can validate negative numbers also.
I like the change in the function signature to include an error. As we can't return -1
when n
is out of range this is the best way to go. 👍
case n < 1000: | ||
h := small[n/100] + " hundred" | ||
s := n % 100 | ||
if s > 0 { | ||
h += " " + Say(s) | ||
temp, _ := Say(s) |
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'm not sure about this variable name, I understand it's to signify temporary, but I think x
would suffice, the use of temp
rather than a letter seems to infer more importance on it than is necessary.
I also think this error should be handled. At this point in the function it shouldn't error out, but still it's better to handle it than ignore it I think.
@@ -9,17 +9,17 @@ Handle the basic case of 0 through 99. | |||
If the input to the program is `22`, then the output should be | |||
`'twenty-two'`. | |||
|
|||
Your program should complain loudly if given a number outside the | |||
blessed range. | |||
Your program should throw an error if given a number outside the |
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 think this can stay as it is.
- -1 | ||
- 100 | ||
- 99 | ||
- 100 (currently an error case) |
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.
With changing the function to use an unsigned int64
I don't think we need to stray from the description in the problem-specifications
repo.
82fb9a6
to
3e89b2c
Compare
This PR has been superseded by #885 Thanks @MatForsberg and sorry this won't be merged. |
In response to issue #837: README suggests to test -1 but the unit tests expect uint64