algo/go/06_linkedlist/singlelinkedlist_test.go
2018-10-05 13:09:20 +08:00

45 lines
735 B
Go

package _6_linkedlist
import "testing"
func TestInsertToHead(t *testing.T) {
l := NewLinkedList()
for i := 0; i < 10; i++ {
l.InsertToHead(i + 1)
}
l.Print()
}
func TestInsertToTail(t *testing.T) {
l := NewLinkedList()
for i := 0; i < 10; i++ {
l.InsertToTail(i + 1)
}
l.Print()
}
func TestFindByIndex(t *testing.T) {
l := NewLinkedList()
for i := 0; i < 10; i++ {
l.InsertToTail(i + 1)
}
t.Log(l.FindByIndex(0))
t.Log(l.FindByIndex(9))
t.Log(l.FindByIndex(5))
t.Log(l.FindByIndex(11))
}
func TestDeleteNode(t *testing.T) {
l := NewLinkedList()
for i := 0; i < 3; i++ {
l.InsertToTail(i + 1)
}
l.Print()
t.Log(l.DeleteNode(l.head.next))
l.Print()
t.Log(l.DeleteNode(l.head.next.next))
l.Print()
}