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

[WIP] say: update tests #867

Closed
wants to merge 4 commits into from
Closed

[WIP] say: update tests #867

wants to merge 4 commits into from

Conversation

MatForsberg
Copy link
Contributor

@MatForsberg MatForsberg commented Sep 20, 2017

In response to issue #837: README suggests to test -1 but the unit tests expect uint64

Mat Forsberg added 2 commits September 20, 2017 15:59
Changed documentation to no longer suggest tests with negative numbers
and clarify necessary error handling.
@robphoenix robphoenix changed the base branch from master to nextercism September 21, 2017 11:29
@robphoenix
Copy link
Contributor

@MatForsberg I've changed the base branch from master to nextercism

@MatForsberg
Copy link
Contributor Author

What do i need to do to get this accepted?

@robphoenix
Copy link
Contributor

robphoenix commented Sep 29, 2017 via email

func Say(n uint64) string {
func Say(n uint64) (string, error) {
if n >= 1000000000000 {
return "", &errorString{"Value out of range."}
Copy link

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

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Good eye @cored thanks!

Copy link
Contributor

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.
@tleen
Copy link
Member

tleen commented Sep 29, 2017

Same here, been swamped a bit. I set aside some gotrack time this weekend and this is top on the list!

@tleen
Copy link
Member

tleen commented Oct 1, 2017

@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 .meta/description.md file. You can see the information on the meta files in our README. Then we can use the configlet to generate the README automatically.

So I think what we should to do here is:

  • add a ./exercises/say/.meta/description.md file with the new information in the README. (Copy the description.md from say and modify to be more specific).
  • also copy the metadata file into ./exercises/say/.meta/metadata.yml (configlet has a bug where it wont process the description.md unless there is a metadata.yml file too: Feature: Add --probSpecsDir option configlet#65.)
  • install configlet locally
  • then in the root of the go track repo execute configlet generate --only say . which will generate the README.md file for say with the changes you made to the description.md file
  • then commit the new generated README.md, and the contents of the .meta/ dir.

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 problem-specifications repo with trask specific stuff. You have identified that our exercise has some really specific instructions that override the general info from problem-specifications so it is a good idea to override the description from there and write our own. It is just that we need to do in in this way to make global changes to the READMEs also work.

It is well thought out I promise! 😅

@robphoenix
Copy link
Contributor

also copy the metadata file into ./exercises/say/.meta/metadata.yml (configlet has a bug where it wont process the description.md unless there is a metadata.yml file too: exercism/configlet#65.)

There is a fix in the pipeline for this: exercism/configlet#84

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.

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) {
Copy link
Contributor

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)
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 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
Copy link
Contributor

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)
Copy link
Contributor

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.

@robphoenix robphoenix changed the title [WIP] Say README suggests to test -1 but the unit tests expect uint64 #837 [WIP] say: update tests Oct 5, 2017
@robphoenix robphoenix force-pushed the nextercism branch 2 times, most recently from 82fb9a6 to 3e89b2c Compare October 10, 2017 08:06
@robphoenix
Copy link
Contributor

This PR has been superseded by #885

Thanks @MatForsberg and sorry this won't be merged.

@robphoenix robphoenix closed this 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