-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_test.go
44 lines (36 loc) · 828 Bytes
/
set_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
package ordmap_test
import (
"testing"
"github.com/MarkRosemaker/ordmap"
)
func (om *UserDefinedOrderedMap) Set(key string, v *ValueWithIndex) {
ordmap.Set(om, key, v, getIndex, setIndex)
}
func TestSet(t *testing.T) {
om := UserDefinedOrderedMap{
"foo": &ValueWithIndex{Foo: "a", Bar: 6, idx: 5},
"bar": &ValueWithIndex{Foo: "b", Bar: 7, idx: 10},
}
om.Set("baz", &ValueWithIndex{Foo: "c", Bar: 8})
if len(om) != 3 {
t.Fatalf("got: %v, want: 3", len(om))
}
i := 0
for _, v := range om.ByIndex() {
switch i {
case 0:
if v.Foo != "a" || v.Bar != 6 || v.idx != 5 {
t.Fatalf("got: %#v", v)
}
case 1:
if v.Foo != "b" || v.Bar != 7 || v.idx != 10 {
t.Fatalf("got: %#v", v)
}
case 2:
if v.Foo != "c" || v.Bar != 8 || v.idx != 11 {
t.Fatalf("got: %#v", v)
}
}
i++
}
}