Skip to content

Commit

Permalink
test: add coverage
Browse files Browse the repository at this point in the history
Signed-off-by: ashing <[email protected]>
  • Loading branch information
ronething committed Jul 16, 2024
1 parent d9cf0f6 commit a34cf66
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
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())
}

0 comments on commit a34cf66

Please sign in to comment.