Skip to content

Commit c56fd62

Browse files
authored
test: add coverage (#228)
Signed-off-by: ashing <[email protected]>
1 parent a8ef844 commit c56fd62

6 files changed

+54
-28
lines changed

go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ go 1.21
44

55
require (
66
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869
7-
github.com/stretchr/testify v1.6.1
7+
github.com/stretchr/testify v1.9.0
88
)
99

1010
require (
11-
github.com/davecgh/go-spew v1.1.0 // indirect
12-
github.com/kr/pretty v0.2.1 // indirect
13-
github.com/kr/text v0.1.0 // indirect
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/kr/pretty v0.3.1 // indirect
13+
github.com/kr/text v0.2.0 // indirect
1414
github.com/pmezard/go-difflib v1.0.0 // indirect
15-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
15+
github.com/rogpeppe/go-internal v1.12.0 // indirect
16+
gopkg.in/yaml.v3 v3.0.1 // indirect
1617
)

go.sum

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
22
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
3-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
4-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
6-
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
7-
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
8-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
9-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
3+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
7+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
8+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
9+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
10+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
1011
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1112
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
13-
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
14-
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
13+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
14+
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
15+
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
16+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
17+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
1518
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1619
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
17-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
18-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
20+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
21+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

leetcode_91_2/2020/0447/447. Number of Boomerangs.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package _447
22

3-
import "fmt"
4-
53
func numberOfBoomerangs(points [][]int) int {
64
res := 0
75
for i := 0; i < len(points); i++ {
@@ -10,7 +8,7 @@ func numberOfBoomerangs(points [][]int) int {
108
if i != j {
119
d := distanceCalc(points[i], points[j])
1210
v, ok := distance[d]
13-
fmt.Printf("d is %v\n", d)
11+
//fmt.Printf("d is %v\n", d)
1412
if ok { // 存在
1513
res += 2 * v // (v+1) * v - [v * (v-1)] = 2 * v
1614
distance[d] += 1

leetcode_91_2/2020/0447/447. Number of Boomerangs_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ func TestNumberOfBoomerangs(t *testing.T) {
1616
}),
1717
"must be 2",
1818
)
19+
assert.Equal(t, 2,
20+
numberOfBoomerangs1([][]int{
21+
{0, 0},
22+
{1, 0},
23+
{2, 0},
24+
}),
25+
"must be 2",
26+
)
1927
}

topic/stack_queue/225. Implement Stack using Queues.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ type MyStack struct {
55
Queue2 []int
66
}
77

8-
func stackConstructor() MyStack {
9-
return MyStack{
10-
Queue1: make([]int, 0),
11-
Queue2: make([]int, 0),
12-
}
13-
}
14-
158
func (m *MyStack) Push(x int) {
169
if len(m.Queue2) != 0 {
1710
m.Queue2 = append(m.Queue2, x)

topic/stack_queue/225. Implement Stack using Queues_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package stack_queue
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
"github.com/bmizerany/assert"
7+
)
48

59
func TestMyStack_Pop(t *testing.T) {
610
type fields struct {
@@ -41,3 +45,22 @@ func TestMyStack_Pop(t *testing.T) {
4145
})
4246
}
4347
}
48+
49+
func TestMyStack(t *testing.T) {
50+
m := &MyStack{}
51+
52+
assert.Equal(t, true, m.Empty())
53+
// Test when Queue2 is empty
54+
m.Push(1)
55+
if len(m.Queue1) != 1 {
56+
t.Errorf("Expected Queue1 length to be 1, got %d", len(m.Queue1))
57+
}
58+
assert.Equal(t, false, m.Empty())
59+
60+
m.Push(2)
61+
62+
assert.Equal(t, 2, m.Top())
63+
assert.Equal(t, 2, m.Pop())
64+
m.Push(3)
65+
assert.Equal(t, 3, m.Top())
66+
}

0 commit comments

Comments
 (0)