func (tt *TreeTest) TestSlice(t *testing.T) {
	tr := tt.New(t)
	Equal(t, tr.Slice(), []interface{}{})
	tt.FillTree(t, tr)
	Equal(t, tr.Slice(), V)
	tr.Shift()
	Equal(t, tr.Slice(), V[1:])
	tr.Pop()
	Equal(t, tr.Slice(), V[1:len(V)-1])
}
TestSlice tests converting the tree to slice
package tree
import (
	"sort"
	"testing"
	. "github.com/zimmski/container/test/assert"
)
var VRaw = []interface{}{5, 3, 1, 4, 6, 2}
var V = []interface{}{1, 2, 3, 4, 5, 6}
var VLen = len(V)
type TreeTest struct {
	New func(t *testing.T) Tree
}
func (tt *TreeTest) Run(t *testing.T) {
	tt.NewFilledTree(t)
	tt.TestBasic(t)
	tt.TestIterator(t)
	tt.TestChannels(t)
	tt.TestSlice(t)
	tt.TestRemove(t)
	tt.TestClear(t)
	tt.TestCopy(t)
	tt.TestContains(t)
	tt.TestGetSet(t)
	tt.TestFuncs(t)
}
func (tt *TreeTest) FillTree(t *testing.T, tr Tree) {
	for i, va := range VRaw {
		tr.Insert(va)
		Equal(t, tr.Len(), i+1)
		vr, ok := tr.Get(va)
		True(t, ok)
		Equal(t, vr, va)
	}
	Equal(t, tr.Len(), VLen)
	n, ok := tr.First()
	True(t, ok)
	Equal(t, n, V[0])
	n, ok = tr.Last()
	True(t, ok)
	Equal(t, n, V[VLen-1])
}
func (tt *TreeTest) NewFilledTree(t *testing.T) Tree {
	tr := tt.New(t)
	tt.FillTree(t, tr)
	return tr
}
func (tt *TreeTest) TestBasic(t *testing.T) {
	tr := tt.New(t)
	Equal(t, tr.Len(), 0)
	True(t, tr.Empty())
	n, ok := tr.First()
	False(t, ok)
	Nil(t, n)
	n, ok = tr.Last()
	False(t, ok)
	Nil(t, n)
	n, ok = tr.Pop()
	Nil(t, n)
	False(t, ok)
	n, ok = tr.Shift()
	Nil(t, n)
	False(t, ok)
	tt.FillTree(t, tr)
	i := 0
	iter := tr.Iter()
	NotNil(t, iter)
	for i < VLen {
		Equal(t, V[i], iter.Get())
		i++
		iter = iter.Next()
		if i < VLen {
			NotNil(t, iter)
		} else {
			Nil(t, iter)
		}
	}
	i = VLen - 1
	n, ok = tr.Pop()
	for i > -1 && n != nil {
		Equal(t, V[i], n)
		True(t, ok)
		Equal(t, tr.Len(), i)
		if i == 0 {
			True(t, tr.Empty())
		} else {
			False(t, tr.Empty())
		}
		i--
		n, ok = tr.Pop()
	}
	Equal(t, i, -1)
	Nil(t, n)
	False(t, ok)
	Equal(t, tr.Len(), 0)
	True(t, tr.Empty())
	tt.FillTree(t, tr)
	i = 0
	n, ok = tr.Shift()
	for i < VLen && n != nil {
		Equal(t, V[i], n)
		True(t, ok)
		Equal(t, tr.Len(), VLen-i-1)
		i++
		n, ok = tr.Shift()
	}
	Equal(t, i, VLen)
	Nil(t, n)
	Equal(t, tr.Len(), 0)
}
func (tt *TreeTest) TestIterator(t *testing.T) {
	tr := tt.New(t)
	Nil(t, tr.Iter())
	Nil(t, tr.IterBack())
	tr.Insert(V[0])
	iter := tr.Iter()
	NotNil(t, iter)
	Equal(t, V[0], iter.Get())
	Nil(t, iter.Next())
	iter = tr.IterBack()
	NotNil(t, iter)
	Equal(t, V[0], iter.Get())
	Nil(t, iter.Previous())
	tr = tt.NewFilledTree(t)
	i := 0
	for iter = tr.Iter(); iter != nil; iter = iter.Next() {
		Equal(t, iter.Get(), V[i])
		i++
	}
	Equal(t, i, VLen)
	tr = tt.NewFilledTree(t)
	i = VLen - 1
	for iter = tr.IterBack(); iter != nil; iter = iter.Previous() {
		Equal(t, iter.Get(), V[i])
		i--
	}
	Equal(t, i, -1)
	iter = tr.Iter()
	Nil(t, iter.Previous())
	iter = tr.IterBack()
	Nil(t, iter.Next())
	tr = tt.New(t)
	for i := 6; i > -1; i-- {
		tr.Insert(i)
	}
	iter = tr.Iter()
	for i := 0; i <= 6; i++ {
		Equal(t, iter.Get(), i)
		iter = iter.Next()
	}
	Nil(t, iter)
	tr = tt.New(t)
	for i := 0; i < 6; i++ {
		tr.Insert(i)
	}
	iter = tr.Iter()
	for i := 0; i < 6; i++ {
		Equal(t, iter.Get(), i)
		iter = iter.Next()
	}
	Nil(t, iter)
	testFullTree := func(cV []int) {
		max := len(cV) - 1
		tr = tt.New(t)
		for _, v := range cV {
			tr.Insert(v)
		}
		sort.Ints(cV)
		iter = tr.Iter()
		for _, v := range cV {
			Equal(t, iter.Get(), v)
			iter = iter.Next()
		}
		Nil(t, iter)
		iter = tr.Iter()
		i = 0
		for iter.Get() != max {
			Equal(t, iter.Get(), cV[i])
			iter = iter.Next()
			i++
		}
		for iter.Get() != 0 {
			Equal(t, iter.Get(), cV[i])
			iter = iter.Previous()
			i--
		}
		for iter.Get() != max {
			Equal(t, iter.Get(), cV[i])
			iter = iter.Next()
			i++
		}
		Nil(t, iter.Next())
		iter = tr.IterBack()
		i = len(cV) - 1
		for iter.Get() != 0 {
			Equal(t, iter.Get(), cV[i])
			iter = iter.Previous()
			i--
		}
		for iter.Get() != max {
			Equal(t, iter.Get(), cV[i])
			iter = iter.Next()
			i++
		}
		for iter.Get() != 0 {
			Equal(t, iter.Get(), cV[i])
			iter = iter.Previous()
			i--
		}
		Nil(t, iter.Previous())
	}
	testFullTree([]int{7, 3, 2, 0, 1, 5, 4, 6, 11, 9, 8, 10, 13, 12, 14})
	testFullTree([]int{8, 3, 1, 0, 2, 6, 5, 4, 7, 13, 10, 9, 11, 12, 15, 14, 16})
	testFullTree([]int{5, 1, 0, 4, 3, 2})
	tr = tt.NewFilledTree(t)
	iter = tr.Iter()
	for i := 1; i <= 3; i++ {
		Equal(t, iter.Get(), V[i-1])
		iter = iter.Next()
	}
	Equal(t, iter.Get(), V[3])
	for i := 4; i > 0; i-- {
		Equal(t, iter.Get(), V[i-1])
		iter = iter.Previous()
	}
	Nil(t, iter)
	iter = tr.IterBack()
	for i := 6; i > 3; i-- {
		Equal(t, iter.Get(), V[i-1])
		iter = iter.Previous()
	}
	Equal(t, iter.Get(), V[2])
	for i := 3; i <= 6; i++ {
		Equal(t, iter.Get(), V[i-1])
		iter = iter.Next()
	}
	Nil(t, iter)
}
func (tt *TreeTest) TestChannels(t *testing.T) {
	tr := tt.New(t)
	i := 0
	for v := range tr.Chan(0) {
		Equal(t, v, V[i])
		i++
	}
	Equal(t, i, 0)
	i = 0
	for v := range tr.ChanBack(0) {
		Equal(t, v, V[i])
		i++
	}
	Equal(t, i, 0)
	tr.Insert(1)
	i = 0
	for v := range tr.Chan(0) {
		Equal(t, v, V[i])
		i++
	}
	Equal(t, i, 1)
	i = 0
	for v := range tr.ChanBack(0) {
		Equal(t, v, V[i])
		i++
	}
	Equal(t, i, 1)
	tr = tt.NewFilledTree(t)
	i = 0
	for v := range tr.Chan(0) {
		Equal(t, v, V[i])
		i++
	}
	Equal(t, i, VLen)
	i = VLen - 1
	for v := range tr.ChanBack(0) {
		Equal(t, v, V[i])
		i--
	}
	Equal(t, i, -1)
}