Skip to content

Commit

Permalink
Add unit tests for priorityQueue.Swap.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyanchen committed May 10, 2023
1 parent a0eadf2 commit 20c3c20
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions policy/lfu/priority_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lfu

import (
"container/heap"
"reflect"
"testing"
"time"
)
Expand Down Expand Up @@ -73,3 +74,42 @@ func TestPriorityQueue(t *testing.T) {
t.Errorf("want %d, but got %d", want, got)
}
}

func Test_priorityQueue_Swap(t *testing.T) {
type args struct {
i int
j int
}
type testCase[K comparable, V any] struct {
name string
q *priorityQueue[K, V]
args args
want *priorityQueue[K, V]
}
tests := []testCase[string, int]{
{
name: "swap case",
q: func() *priorityQueue[string, int] {
q := newPriorityQueue[string, int](10)
q.Push(&entry[string, int]{index: 0})
q.Push(&entry[string, int]{index: 1})
return q
}(),
args: args{i: 0, j: 1},
want: func() *priorityQueue[string, int] {
q := newPriorityQueue[string, int](10)
q.Push(&entry[string, int]{index: 1})
q.Push(&entry[string, int]{index: 0})
return q
}(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.q.Swap(tt.args.i, tt.args.j)
if !reflect.DeepEqual(tt.q, tt.want) {
t.Errorf("want %v, got %v", tt.want, tt.q)
}
})
}
}

0 comments on commit 20c3c20

Please sign in to comment.