forked from elliotchance/orderedmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelement_test.go
67 lines (56 loc) · 1.42 KB
/
element_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package orderedmap_test
import (
"github.com/elliotchance/orderedmap"
"github.com/stretchr/testify/assert"
"testing"
)
func TestElement_Key(t *testing.T) {
t.Run("Front", func(t *testing.T) {
m := orderedmap.NewOrderedMap()
m.Set(1, "foo")
m.Set(2, "bar")
assert.Equal(t, 1, m.Front().Key)
})
t.Run("Back", func(t *testing.T) {
m := orderedmap.NewOrderedMap()
m.Set(1, "foo")
m.Set(2, "bar")
assert.Equal(t, 2, m.Back().Key)
})
}
func TestElement_Value(t *testing.T) {
t.Run("Front", func(t *testing.T) {
m := orderedmap.NewOrderedMap()
m.Set(1, "foo")
m.Set(2, "bar")
assert.Equal(t, "foo", m.Front().Value)
})
t.Run("Back", func(t *testing.T) {
m := orderedmap.NewOrderedMap()
m.Set(1, "foo")
m.Set(2, "bar")
assert.Equal(t, "bar", m.Back().Value)
})
}
func TestElement_Next(t *testing.T) {
m := orderedmap.NewOrderedMap()
m.Set(1, "foo")
m.Set(2, "bar")
m.Set(3, "baz")
var results []interface{}
for el := m.Front(); el != nil; el = el.Next() {
results = append(results, el.Key, el.Value)
}
assert.Equal(t, []interface{}{1, "foo", 2, "bar", 3, "baz"}, results)
}
func TestElement_Prev(t *testing.T) {
m := orderedmap.NewOrderedMap()
m.Set(1, "foo")
m.Set(2, "bar")
m.Set(3, "baz")
var results []interface{}
for el := m.Back(); el != nil; el = el.Prev() {
results = append(results, el.Key, el.Value)
}
assert.Equal(t, []interface{}{3, "baz", 2, "bar", 1, "foo"}, results)
}