| 1 |
package skip |
| 2 |
|
| 3 |
import ( |
| 4 |
|
| 5 |
"testing" |
| 6 |
) |
| 7 |
|
| 8 |
func Test(t *testing.T) { |
| 9 |
sl := New(func(a,b interface{})bool { |
| 10 |
return a.(int) < b.(int) |
| 11 |
}) |
| 12 |
sl.Insert(1, 100) |
| 13 |
if sl.Len() != 1 { |
| 14 |
t.Errorf("expecting len 1") |
| 15 |
} |
| 16 |
sl.Insert(1, 1000) |
| 17 |
if sl.Len() != 1 { |
| 18 |
t.Errorf("expecting len 1") |
| 19 |
} |
| 20 |
if sl.Get(1).(int) != 1000 { |
| 21 |
t.Errorf("expecting sl[1] == 1000") |
| 22 |
} |
| 23 |
sl.Remove(1) |
| 24 |
if sl.Len() != 0 { |
| 25 |
t.Errorf("expecting len 0") |
| 26 |
} |
| 27 |
|
| 28 |
sl.Insert(2, 200) |
| 29 |
sl.Insert(1, 100) |
| 30 |
vs := make([]int, 0) |
| 31 |
sl.Do(func(k, v interface{}) bool { |
| 32 |
vs = append(vs, k.(int)) |
| 33 |
return true |
| 34 |
}) |
| 35 |
if len(vs) != 2 || vs[0] != 1 || vs[1] != 2 { |
| 36 |
t.Errorf("expecting sorted iteration of all keys") |
| 37 |
} |
| 38 |
} |