func TestIterate(t *testing.T) {

	test := func(table Map) {
		t.Logf("%T", table)
		for k, v, next := table.Iterate()(); next != nil; k, v, next = next() {
			t.Errorf("Should never reach here %v %v %v", k, v, next)
		}
		records := make(map[String]String)
		for i := 0; i < 100; i++ {
			k := randstr(8)
			v := randstr(8)
			records[k] = v
			err := table.Put(k, String(""))
			if err != nil {
				t.Error(err)
			}
			err = table.Put(k, v)
			if err != nil {
				t.Error(err)
			}
			if table.Size() != (i + 1) {
				t.Error("size was wrong", table.Size(), i+1)
			}
		}
		newrecs := make(map[String]String)
		for k, v, next := table.Iterate()(); next != nil; k, v, next = next() {
			if v2, has := records[k.(String)]; !has {
				t.Error("bad key in table")
			} else if !v2.Equals(v.(Equatable)) {
				t.Error("values don't agree")
			}
			newrecs[k.(String)] = v.(String)
		}
		if len(records) != len(newrecs) {
			t.Error("iterate missed records")
		}
		for k, v := range records {
			if v2, has := newrecs[k]; !has {
				t.Error("key went missing")
			} else if !v2.Equals(v) {
				t.Error("values don't agree")
			}
		}
	}
	test(NewHashTable(64))
	test(NewLinearHash())
	test(avl.NewAvlTree())
	test(avl.NewImmutableAvlTree())
}
func TestImmutableAvlTreeCast(t *testing.T) {
	tree := avl.NewImmutableAvlTree()
	_ = types.TreeMap(tree)
}