torrent/ordered_test.go

48 lines
682 B
Go
Raw Normal View History

2014-07-09 14:26:58 +00:00
package torrent
import (
"testing"
)
func TestOrderedList(t *testing.T) {
2015-03-08 06:28:14 +00:00
ol := newOrderedList(func(a, b interface{}) bool {
2014-07-09 14:26:58 +00:00
return a.(int) < b.(int)
})
if ol.Len() != 0 {
t.FailNow()
}
e := ol.Insert(0)
if ol.Len() != 1 {
t.FailNow()
}
if e.Value.(int) != 0 {
t.FailNow()
}
e = ol.Front()
if e.Value.(int) != 0 {
t.FailNow()
}
if e.Next() != nil {
t.FailNow()
}
ol.Insert(1)
if e.Next().Value.(int) != 1 {
t.FailNow()
}
ol.Insert(-1)
if e.Prev().Value.(int) != -1 {
t.FailNow()
}
e.Value = -2
ol.ValueChanged(e)
if e.Prev() != nil {
t.FailNow()
}
if e.Next().Value.(int) != -1 {
t.FailNow()
}
if ol.Len() != 3 {
t.FailNow()
}
}