Skip to content

Commit 2a13ed5

Browse files
committed
Add test for List.MoveToFront
1 parent 1441ccd commit 2a13ed5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

list_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ func Test_List_Remove(t *testing.T) {
5656
assertList(t, l)
5757
}
5858

59+
func Test_List_MoveToFront(t *testing.T) {
60+
l := NewList[int]()
61+
62+
// Single item - already at front
63+
n1 := newItem("a", 1, 0, false)
64+
l.Insert(n1)
65+
l.MoveToFront(n1)
66+
assertList(t, l, 1)
67+
68+
// Head item - already at front
69+
n2 := newItem("b", 2, 0, false)
70+
l.Insert(n2)
71+
assertList(t, l, 2, 1)
72+
l.MoveToFront(n2)
73+
assertList(t, l, 2, 1)
74+
75+
// Tail item
76+
l.MoveToFront(n1)
77+
assertList(t, l, 1, 2)
78+
79+
// Middle item
80+
n3 := newItem("c", 3, 0, false)
81+
l.Insert(n3)
82+
assertList(t, l, 3, 1, 2)
83+
l.MoveToFront(n1)
84+
assertList(t, l, 1, 3, 2)
85+
}
86+
5987
func assertList(t *testing.T, list *List[int], expected ...int) {
6088
t.Helper()
6189

0 commit comments

Comments
 (0)