Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-kim committed Oct 4, 2023
1 parent dac0d55 commit 66155f0
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions utils/heap/set_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package heap

import (
"github.com/stretchr/testify/require"
"testing"
)

func TestSet(t *testing.T) {
tests := []struct {
name string
setup func(h Set[int])
expected []int
}{
{
name: "only push",
setup: func(h Set[int]) {
h.Push(1)
h.Push(2)
h.Push(3)

},
expected: []int{1, 2, 3},
},
{
name: "out of order pushes",
setup: func(h Set[int]) {
h.Push(1)
h.Push(5)
h.Push(2)
h.Push(4)
h.Push(3)
},
expected: []int{1, 2, 3, 4, 5},
},
{
name: "push and pop",
setup: func(h Set[int]) {
h.Push(1)
h.Push(5)
h.Push(2)
h.Push(4)
h.Push(3)
h.Pop()
h.Pop()
h.Pop()
},
expected: []int{4, 5},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)

h := NewSet[int](func(a, b int) bool {
return a < b
})

tt.setup(h)

require.Equal(len(tt.expected), h.Len())
for _, expected := range tt.expected {
got, ok := h.Pop()
require.True(ok)
require.Equal(expected, got)
}
})
}
}

0 comments on commit 66155f0

Please sign in to comment.