-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Increase consistency of math tutorial with other tutorials #266
Conversation
Trims test output, assumes a single test file, other tweaks.
Also, overall comment: this tutorial uses the phrase "acceptance test" and seems (in the repo) to place some tests in clock_acceptance_test.go and the rest in clock_test.go. I found that confusing as it wasn't clear what we were putting where, and would appreciate a formal introduction to "acceptance test" (the way you're using it) and guidance on file structure (if you think we should indeed split the test files). |
@@ -95,20 +95,18 @@ focus on testing something that creates them. | |||
So my first test looks like this: | |||
|
|||
```go | |||
package clockface_test | |||
package clockface |
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.
This is an example of a test file that seemed to think it was testing functionality in a different package. I changed the package name and removed "clockface" in front of the functions.
``` | ||
|
||
### Write enough code to make it pass | ||
|
||
When we get the expected failure, we can fill in the return value of `HandsAt`: | ||
When we get the expected failure, we can fill in the return value of `SecondHand`: |
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.
Typo
@@ -183,7 +174,7 @@ Behold, a passing test. | |||
|
|||
``` | |||
PASS | |||
ok github.com/gypsydave5/learn-go-with-tests/math/v1/clockface 0.006s | |||
ok clockface 0.006s |
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.
This is an example of simplifying the passing tests output. I got confused at first by all the github.com/gypsydave5 references (as it was also in the imports for a few files), so I thought removing all the references might reduce confusion. However, I realize now that Go always outputs the full path so this simplification may suffer accuracy.
hard work for us. Even better, there's an online version at | ||
[https://www.onlinetool.io/xmltogo/](https://www.onlinetool.io/xmltogo/). Just | ||
paste the SVG from the top of the file into one box and - bam | ||
- out pops: | ||
paste the SVG from the top of the file into one box and - bam! - out pops: |
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.
When the hyphen is on a new line , it makes a bulleted list instead. Fixed this in a few places.
@@ -952,14 +903,16 @@ type Svg struct { | |||
``` | |||
|
|||
We could make adjustments to this if we needed to (like changing the name of the | |||
struct to `SVG`) but it's definitely good enough to start us off. | |||
struct to `SVG`) but it's definitely good enough to start us off. Paste that struct into the same file as the clockface functions. |
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.
Actually, looks like you wanted this in the test file, so I should edit this! TODO.
@@ -1020,7 +957,7 @@ func secondHand(w io.Writer, t time.Time) { | |||
p = Point{p.X * secondHandLength, p.Y * secondHandLength} // scale | |||
p = Point{p.X, -p.Y} // flip | |||
p = Point{p.X + clockCentreX, p.Y + clockCentreY} // translate | |||
fmt.Fprintf(w, `<line x1="150" y1="150" x2="%.3f" y2="%.3f" style="fill:none;stroke:#f00;stroke-width:3px;"/>`, p.X, p.Y) | |||
fmt.Fprintf(w, `<line x1="150" y1="150" x2="%f" y2="%f" style="fill:none;stroke:#f00;stroke-width:3px;"/>`, p.X, p.Y) |
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.
This code had a spoiler alert
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 spot 👍
@@ -1118,8 +1042,8 @@ tests, to sharpen everything up. | |||
type SVG struct { | |||
XMLName xml.Name `xml:"svg"` | |||
Xmlns string `xml:"xmlns,attr"` | |||
Width float64 `xml:"width,attr"` | |||
Height float64 `xml:"height,attr"` | |||
Width string `xml:"width,attr"` |
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.
width is 100%, so these needed to stay strings, else it failed to parse for me
But the proof of the pudding is in the eating - if we now compile and run our | ||
`clockface` program, we should see something like | ||
|
||
![a clock with second and minute hands](math/v9/clockface/clockface/clock.svg) | ||
![a clock with only a second hand](math/v9/clockface/clockface/clock.svg) |
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.
Not sure why this reverted. TODO
``` | ||
|
||
### Write enough code to make it pass | ||
|
||
And we can now make our final adjustments to `svgWriter.go` | ||
And we can now make our final adjustments to the SVG writing constants and functions: |
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.
The tutorial never mentioned a svgWriter.go
file before. I'd suggest it mentioning it earlier, if the goal is for us to split the functions like that.
@@ -2122,7 +2010,7 @@ document how it works. | |||
> a C program. | |||
> -- Henry Spencer, in _The Art of Unix Programming_ | |||
|
|||
In [my final take on this program](math/vFinal/clockface), I've made the | |||
In [my final take on this program](https://github.com/gypsydave5/learn-go-with-tests/tree/master/math/vFinal/clockface), I've made 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.
Current URL 404s
Wow, thanks for all this effort @pamelafox I will try and find some time to look at this over the coming week |
This is fair, if I've not introduced this idea it's because I thought @quii had already done it for me... the basic principle is that an 'acceptance' test is testing the behaviour you want to achieve from the point of view of a user (to be 'accepted' by them), whereas 'unit' tests are usually working at a lower level than the surface of the application. These are not well defined terms though! I'll try and work something up to explain this division. |
@gypsydave5 The other type of test I've seen introduced are integration tests, in the web application tutorial. That would still come after your SVG tutorial, though, and an integration test isn't the same as acceptance test. (They might happen to be the same in this case, but wouldn't always be). Here's where integration tests are introduced: https://quii.gitbook.io/learn-go-with-tests/build-an-application/http-server#integration-tests |
Just commenting to remind myself of the shame of this. I am going to try and get someone (@gypsydave5 cough) to pair with me on this next year to get it merged. Really sorry @pamelafox |
No worries, I'm similarly a year behind on responding to OSS PRs. :) |
(and a few by me) This is easier than me trying to work through the diff which I failed at for the last twelve months. The original PR is quii#266 Apologies that it took so long. Co-authored-by: Pamela Fox <pamela.fox@gmail.com>
OK - hey @pamelafox and @quii - I've gone through the changes in a separate PR one by one and added in all the ones I agree with - which is most of them! - along with a few other changes I've wanted to make. @pamelafox I've tagged you as a co-author, is this OK? |
(and a few by me) This is easier than me trying to work through the diff which I failed at for the last twelve months. The original PR is quii#266 Apologies that it took so long. Co-authored-by: Pamela Fox <pamela.fox@gmail.com>
Sounds good, I'll close this one! |
(and a few by me) This is easier than me trying to work through the diff which I failed at for the last twelve months. The original PR is #266 Apologies that it took so long. Co-authored-by: Pamela Fox <pamela.fox@gmail.com> Co-authored-by: Pamela Fox <pamela.fox@gmail.com>
(and a few by me) This is easier than me trying to work through the diff which I failed at for the last twelve months. The original PR is #266 Apologies that it took so long. Co-authored-by: Pamela Fox <pamela.fox@gmail.com> Co-authored-by: Pamela Fox <pamela.fox@gmail.com>
(and a few by me) This is easier than me trying to work through the diff which I failed at for the last twelve months. The original PR is quii#266 Apologies that it took so long. Co-authored-by: Pamela Fox <pamela.fox@gmail.com> Co-authored-by: Pamela Fox <pamela.fox@gmail.com>
(and a few by me) This is easier than me trying to work through the diff which I failed at for the last twelve months. The original PR is quii#266 Apologies that it took so long. Co-authored-by: Pamela Fox <pamela.fox@gmail.com> Co-authored-by: Pamela Fox <pamela.fox@gmail.com>
Thanks for the tutorial, @gypsydave5!
I noticed various inconsistencies with the math tutorial as compared to the other tutorials in terms of test output display and package organization. Specifically:
clockface.SecondHand
). I change them to assume they're in same package.I'll add in-line comments as well.