|
|
|
@ -6,8 +6,9 @@ package doublylinkedlist
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/emirpasic/gods/utils"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/emirpasic/gods/utils"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestListAdd(t *testing.T) {
|
|
|
|
@ -177,6 +178,32 @@ func TestListInsert(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestListSet(t *testing.T) {
|
|
|
|
|
list := New()
|
|
|
|
|
list.Set(0, "a")
|
|
|
|
|
list.Set(1, "b")
|
|
|
|
|
if actualValue := list.Size(); actualValue != 2 {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, 2)
|
|
|
|
|
}
|
|
|
|
|
list.Set(2, "c") // append
|
|
|
|
|
if actualValue := list.Size(); actualValue != 3 {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, 3)
|
|
|
|
|
}
|
|
|
|
|
list.Set(4, "d") // ignore
|
|
|
|
|
list.Set(1, "bb") // update
|
|
|
|
|
if actualValue := list.Size(); actualValue != 3 {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, 3)
|
|
|
|
|
}
|
|
|
|
|
if actualValue, expectedValue := fmt.Sprintf("%s%s%s", list.Values()...), "abbc"; actualValue != expectedValue {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
list.Set(2, "cc") // last to first traversal
|
|
|
|
|
list.Set(0, "aa") // first to last traversal
|
|
|
|
|
if actualValue, expectedValue := fmt.Sprintf("%s%s%s", list.Values()...), "aabbcc"; actualValue != expectedValue {
|
|
|
|
|
t.Errorf("Got %v expected %v", actualValue, expectedValue)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestListEach(t *testing.T) {
|
|
|
|
|
list := New()
|
|
|
|
|
list.Add("a", "b", "c")
|
|
|
|
|