@@ -27,16 +27,16 @@ func TestAssertFunctions(t *testing.T) {
27
27
}
28
28
29
29
func AssertEqual (t *testing .T , got , want int ) {
30
- t.Helper ()
30
+ t.Helper ()
31
31
if got != want {
32
32
t.Errorf (" got %d , want %d " , got, want)
33
33
}
34
34
}
35
35
36
36
func AssertNotEqual (t *testing .T , got , want int ) {
37
- t.Helper ()
37
+ t.Helper ()
38
38
if got == want {
39
- t.Errorf (" didn't want %d " , got)
39
+ t.Errorf (" didn't want %d " , got)
40
40
}
41
41
}
42
42
```
@@ -48,8 +48,8 @@ Being able to assert on the equality of integers is great but what if we want to
48
48
49
49
``` go
50
50
t.Run (" asserting on strings" , func (t *testing.T ) {
51
- AssertEqual (t, " hello" , " hello" )
52
- AssertNotEqual (t, " hello" , " Grace" )
51
+ AssertEqual (t, " hello" , " hello" )
52
+ AssertNotEqual (t, " hello" , " Grace" )
53
53
})
54
54
```
55
55
@@ -138,14 +138,14 @@ func TestAssertFunctions(t *testing.T) {
138
138
}
139
139
140
140
func AssertEqual [T comparable](t *testing.T , got, want T ) {
141
- t.Helper ()
141
+ t.Helper ()
142
142
if got != want {
143
143
t.Errorf (" got %v , want %v " , got, want)
144
144
}
145
145
}
146
146
147
147
func AssertNotEqual [T comparable](t *testing.T , got, want T ) {
148
- t.Helper ()
148
+ t.Helper ()
149
149
if got == want {
150
150
t.Errorf (" didn't want %v " , got)
151
151
}
@@ -379,13 +379,13 @@ Add the following test,
379
379
380
380
` ` ` go
381
381
t.Run (" interface stack dx is horrid" , func (t *testing.T ) {
382
- myStackOfInts := new (StackOfInts)
382
+ myStackOfInts := new (StackOfInts)
383
383
384
- myStackOfInts.Push (1 )
385
- myStackOfInts.Push (2 )
386
- firstNum , _ := myStackOfInts.Pop ()
387
- secondNum , _ := myStackOfInts.Pop ()
388
- AssertEqual (firstNum+secondNum, 3 )
384
+ myStackOfInts.Push (1 )
385
+ myStackOfInts.Push (2 )
386
+ firstNum , _ := myStackOfInts.Pop ()
387
+ secondNum , _ := myStackOfInts.Pop ()
388
+ AssertEqual (firstNum+secondNum, 3 )
389
389
})
390
390
```
391
391
@@ -401,21 +401,21 @@ To get around this, the caller has to do a [type assertion](https://golang.org/r
401
401
402
402
``` go
403
403
t.Run (" interface stack dx is horrid" , func (t *testing.T ) {
404
- myStackOfInts := new (StackOfInts)
404
+ myStackOfInts := new (StackOfInts)
405
405
406
- myStackOfInts.Push (1 )
407
- myStackOfInts.Push (2 )
408
- firstNum , _ := myStackOfInts.Pop ()
409
- secondNum , _ := myStackOfInts.Pop ()
406
+ myStackOfInts.Push (1 )
407
+ myStackOfInts.Push (2 )
408
+ firstNum , _ := myStackOfInts.Pop ()
409
+ secondNum , _ := myStackOfInts.Pop ()
410
410
411
- // get our ints from out interface{}
412
- reallyFirstNum , ok := firstNum.(int )
413
- AssertTrue (t, ok) // need to check we definitely got an int out of the interface{}
411
+ // get our ints from out interface{}
412
+ reallyFirstNum , ok := firstNum.(int )
413
+ AssertTrue (t, ok) // need to check we definitely got an int out of the interface{}
414
414
415
- reallySecondNum , ok := secondNum.(int )
416
- AssertTrue (t, ok) // and again!
415
+ reallySecondNum , ok := secondNum.(int )
416
+ AssertTrue (t, ok) // and again!
417
417
418
- AssertEqual (t, reallyFirstNum+reallySecondNum, 3 )
418
+ AssertEqual (t, reallyFirstNum+reallySecondNum, 3 )
419
419
})
420
420
```
421
421
@@ -429,27 +429,27 @@ Here's our new `Stack` implementation, featuring a generic data type.
429
429
430
430
``` go
431
431
type Stack [T any] struct {
432
- values []T
432
+ values []T
433
433
}
434
434
435
435
func (s *Stack [T ]) Push (value T ) {
436
- s.values = append (s.values , value)
436
+ s.values = append (s.values , value)
437
437
}
438
438
439
439
func (s *Stack [T ]) IsEmpty () bool {
440
- return len (s.values )==0
440
+ return len (s.values )==0
441
441
}
442
442
443
443
func (s *Stack [T ]) Pop () (T , bool ) {
444
- if s.IsEmpty () {
445
- var zero T
446
- return zero, false
447
- }
448
-
449
- index := len (s.values ) -1
450
- el := s.values [index]
451
- s.values = s.values [:index]
452
- return el, true
444
+ if s.IsEmpty () {
445
+ var zero T
446
+ return zero, false
447
+ }
448
+
449
+ index := len (s.values ) -1
450
+ el := s.values [index]
451
+ s.values = s.values [:index]
452
+ return el, true
453
453
}
454
454
```
455
455
@@ -489,7 +489,7 @@ You'll notice the syntax for defining generic data structures is consistent with
489
489
490
490
``` go
491
491
type Stack [T any] struct {
492
- values []T
492
+ values []T
493
493
}
494
494
```
495
495
0 commit comments