Skip to content

Commit

Permalink
heapq: clean up package aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Sep 13, 2024
1 parent 6a13e56 commit aedc589
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions heapq/heapq_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package heapq_test

import (
stdcmp "cmp"
"cmp"
"math/rand/v2"
"sort"
"testing"

"github.com/creachadair/mds/compare"
"github.com/creachadair/mds/heapq"
"github.com/creachadair/mds/internal/mdtest"
"github.com/google/go-cmp/cmp"
gocmp "github.com/google/go-cmp/cmp"
)

var _ mdtest.Shared[any] = (*heapq.Queue[any])(nil)

func intCompare(a, b int) int { return stdcmp.Compare(a, b) }
func revIntCompare(a, b int) int { return stdcmp.Compare(b, a) }
var intCompare = cmp.Compare[int]
var revIntCompare = compare.Reversed(cmp.Compare[int])

func TestHeap(t *testing.T) {
t.Run("New", func(t *testing.T) {
Expand All @@ -35,7 +36,7 @@ func runTests(t *testing.T, q *heapq.Queue[int]) {
for v := range q.Each {
got = append(got, v)
}
if diff := cmp.Diff(want, got); diff != "" {
if diff := gocmp.Diff(want, got); diff != "" {
t.Errorf("Queue contents (+want, -got):\n%s", diff)
t.Logf("Got: %v", got)
t.Logf("Want: %v", want)
Expand Down Expand Up @@ -184,7 +185,7 @@ func TestNewWithData(t *testing.T) {
sort.Ints(got)
sort.Ints(want)

if diff := cmp.Diff(want, got); diff != "" {
if diff := gocmp.Diff(want, got); diff != "" {
t.Errorf("Queue contents (+want, -got):\n%s", diff)
}
}
Expand Down Expand Up @@ -218,7 +219,7 @@ func TestSort(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
in := append([]int(nil), tc.input...)
heapq.Sort(tc.cmp, in)
if diff := cmp.Diff(tc.want, in); diff != "" {
if diff := gocmp.Diff(tc.want, in); diff != "" {
t.Errorf("Sort (-want, +got):\n%s", diff)
}
})
Expand All @@ -228,7 +229,7 @@ func TestSort(t *testing.T) {
func TestUpdate(t *testing.T) {
m := make(map[string]int) // tracks the offsets of strings in the queue
up := func(s string, p int) { m[s] = p } // update the offsets map
q := heapq.New(stdcmp.Compare[string]).Update(up)
q := heapq.New(cmp.Compare[string]).Update(up)

// Verify that all the elements know their current offset correctly.
check := func() {
Expand Down Expand Up @@ -273,7 +274,7 @@ func TestUpdate(t *testing.T) {
}

}
if diff := cmp.Diff(got, []string{"a", "b", "c", "k", "m", "t", "z"}); diff != "" {
if diff := gocmp.Diff(got, []string{"a", "b", "c", "k", "m", "t", "z"}); diff != "" {
t.Errorf("Values (-got, +want):\n%s", diff)
}
}
Expand Down

0 comments on commit aedc589

Please sign in to comment.