]> Sergey Matveev's repositories - btrtrc.git/blob - ordered_test.go
More cleaning of public interface
[btrtrc.git] / ordered_test.go
1 package torrent
2
3 import (
4         "testing"
5 )
6
7 func TestOrderedList(t *testing.T) {
8         ol := newOrderedList(func(a, b interface{}) bool {
9                 return a.(int) < b.(int)
10         })
11         if ol.Len() != 0 {
12                 t.FailNow()
13         }
14         e := ol.Insert(0)
15         if ol.Len() != 1 {
16                 t.FailNow()
17         }
18         if e.Value.(int) != 0 {
19                 t.FailNow()
20         }
21         e = ol.Front()
22         if e.Value.(int) != 0 {
23                 t.FailNow()
24         }
25         if e.Next() != nil {
26                 t.FailNow()
27         }
28         ol.Insert(1)
29         if e.Next().Value.(int) != 1 {
30                 t.FailNow()
31         }
32         ol.Insert(-1)
33         if e.Prev().Value.(int) != -1 {
34                 t.FailNow()
35         }
36         e.Value = -2
37         ol.ValueChanged(e)
38         if e.Prev() != nil {
39                 t.FailNow()
40         }
41         if e.Next().Value.(int) != -1 {
42                 t.FailNow()
43         }
44         if ol.Len() != 3 {
45                 t.FailNow()
46         }
47 }