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

test: add coverage #228

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ go 1.21

require (
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.9.0
)

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

import "fmt"

func numberOfBoomerangs(points [][]int) int {
res := 0
for i := 0; i < len(points); i++ {
Expand All @@ -10,7 +8,7 @@ func numberOfBoomerangs(points [][]int) int {
if i != j {
d := distanceCalc(points[i], points[j])
v, ok := distance[d]
fmt.Printf("d is %v\n", d)
//fmt.Printf("d is %v\n", d)
if ok { // 存在
res += 2 * v // (v+1) * v - [v * (v-1)] = 2 * v
distance[d] += 1
Expand Down
8 changes: 8 additions & 0 deletions leetcode_91_2/2020/0447/447. Number of Boomerangs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ func TestNumberOfBoomerangs(t *testing.T) {
}),
"must be 2",
)
assert.Equal(t, 2,
numberOfBoomerangs1([][]int{
{0, 0},
{1, 0},
{2, 0},
}),
"must be 2",
)
}
7 changes: 0 additions & 7 deletions topic/stack_queue/225. Implement Stack using Queues.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ type MyStack struct {
Queue2 []int
}

func stackConstructor() MyStack {
return MyStack{
Queue1: make([]int, 0),
Queue2: make([]int, 0),
}
}

func (m *MyStack) Push(x int) {
if len(m.Queue2) != 0 {
m.Queue2 = append(m.Queue2, x)
Expand Down
25 changes: 24 additions & 1 deletion topic/stack_queue/225. Implement Stack using Queues_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package stack_queue

import "testing"
import (
"testing"

"github.com/bmizerany/assert"
)

func TestMyStack_Pop(t *testing.T) {
type fields struct {
Expand Down Expand Up @@ -41,3 +45,22 @@ func TestMyStack_Pop(t *testing.T) {
})
}
}

func TestMyStack(t *testing.T) {
m := &MyStack{}

assert.Equal(t, true, m.Empty())
// Test when Queue2 is empty
m.Push(1)
if len(m.Queue1) != 1 {
t.Errorf("Expected Queue1 length to be 1, got %d", len(m.Queue1))
}
assert.Equal(t, false, m.Empty())

m.Push(2)

assert.Equal(t, 2, m.Top())
assert.Equal(t, 2, m.Pop())
m.Push(3)
assert.Equal(t, 3, m.Top())
}
Loading