You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: integers.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
3
3
**[You can find all the code for this chapter here](https://github.com/quii/learn-go-with-tests/tree/master/integers)**
4
4
5
-
Integers work as you would expect. Let's write an add function to try things out. Create a test file called `adder_test.go` and write this code.
5
+
Integers work as you would expect. Let's write an `Add` function to try things out. Create a test file called `adder_test.go` and write this code.
6
6
7
-
**note:** Go source files can only have one `package` per directory, make sure that your files are organised separately. [Here is a good explanation on this.](https://dave.cheney.net/2014/12/01/five-suggestions-for-setting-up-a-go-project)
7
+
**Note:** Go source files can only have one `package` per directory, make sure that your files are organised separately. [Here is a good explanation on this.](https://dave.cheney.net/2014/12/01/five-suggestions-for-setting-up-a-go-project)
8
8
9
9
## Write the test first
10
10
@@ -25,7 +25,7 @@ func TestAdder(t *testing.T) {
25
25
26
26
You will notice that we're using `%d` as our format strings rather than `%q`. That's because we want it to print an integer rather than a string.
27
27
28
-
Also note that we are no longer using the main package, instead we've defined a package named integers, as the name suggests this will group functions for working with integers such as Add.
28
+
Also note that we are no longer using the main package, instead we've defined a package named `integers`, as the name suggests this will group functions for working with integers such as `Add`.
29
29
30
30
## Try and run the test
31
31
@@ -67,9 +67,9 @@ func Add(x, y int) int {
67
67
68
68
Ah hah! Foiled again, TDD is a sham right?
69
69
70
-
We could write another test, with some different numbers to force that test to fail but that feels like a game of cat and mouse.
70
+
We could write another test, with some different numbers to force that test to fail but that feels like [a game of cat and mouse](https://en.m.wikipedia.org/wiki/Cat_and_mouse).
71
71
72
-
Once we're more familiar with Go's syntax I will introduce a technique called Property Based Testing, which would stop annoying developers and help you find bugs.
72
+
Once we're more familiar with Go's syntax I will introduce a technique called *"Property Based Testing"*, which would stop annoying developers and help you find bugs.
73
73
74
74
For now, let's fix it properly
75
75
@@ -108,7 +108,7 @@ Go examples are executed just like tests so you can be confident examples reflec
108
108
109
109
Examples are compiled \(and optionally executed\) as part of a package's test suite.
110
110
111
-
As with typical tests, examples are functions that reside in a package's \_test.go files. Add the following ExampleAdd function to the `adder_test.go` file.
111
+
As with typical tests, examples are functions that reside in a package's `_test.go` files. Add the following `ExampleAdd` function to the `adder_test.go` file.
112
112
113
113
```go
114
114
funcExampleAdd() {
@@ -132,7 +132,7 @@ $ go test -v
132
132
--- PASS: ExampleAdd (0.00s)
133
133
```
134
134
135
-
Please note that the example function will not be executed if you remove the comment "//Output: 6". Although the function will be compiled, it won't be executed.
135
+
Please note that the example function will not be executed if you remove the comment `//Output: 6`. Although the function will be compiled, it won't be executed.
136
136
137
137
By adding this code the example will appear in the documentation inside `godoc`, making your code even more accessible.
0 commit comments