diff --git a/go.mod b/go.mod index 3d4101b..6c87886 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 336a246..cd76fc7 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/leetcode_91_2/2020/0447/447. Number of Boomerangs.go b/leetcode_91_2/2020/0447/447. Number of Boomerangs.go index eb78905..1100c6c 100644 --- a/leetcode_91_2/2020/0447/447. Number of Boomerangs.go +++ b/leetcode_91_2/2020/0447/447. Number of Boomerangs.go @@ -1,7 +1,5 @@ package _447 -import "fmt" - func numberOfBoomerangs(points [][]int) int { res := 0 for i := 0; i < len(points); i++ { @@ -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 diff --git a/leetcode_91_2/2020/0447/447. Number of Boomerangs_test.go b/leetcode_91_2/2020/0447/447. Number of Boomerangs_test.go index 72d6da3..8160cd2 100644 --- a/leetcode_91_2/2020/0447/447. Number of Boomerangs_test.go +++ b/leetcode_91_2/2020/0447/447. Number of Boomerangs_test.go @@ -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", + ) } diff --git a/topic/stack_queue/225. Implement Stack using Queues.go b/topic/stack_queue/225. Implement Stack using Queues.go index 0b02546..efe615e 100644 --- a/topic/stack_queue/225. Implement Stack using Queues.go +++ b/topic/stack_queue/225. Implement Stack using Queues.go @@ -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) diff --git a/topic/stack_queue/225. Implement Stack using Queues_test.go b/topic/stack_queue/225. Implement Stack using Queues_test.go index e9341f5..d3b4b90 100644 --- a/topic/stack_queue/225. Implement Stack using Queues_test.go +++ b/topic/stack_queue/225. Implement Stack using Queues_test.go @@ -1,6 +1,10 @@ package stack_queue -import "testing" +import ( + "testing" + + "github.com/bmizerany/assert" +) func TestMyStack_Pop(t *testing.T) { type fields struct { @@ -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()) +}