package utils import ( "math" "reflect" "testing" ) const ( a = 0x00001 b = 0x00010 c = 0x00100 ) func TestArrayFlip(t *testing.T) { //flip := []uint64{1, 2, 3, 4} //out := ArrayFlip(flip) //t.Logf("out:%v\n", out) //d := a & b & c //t.Log(d) //a := make([]int, 5) //t.Log(a) //t.Log(a[4]) //a = append(a, []int{1, 2, 3, 4, 5, 6, 7, 8, 9}...) //t.Log(a) //t.Log(len(a)) //t.Log(cap(a)) t.Log(math.Sqrt(4)) } func TestArrayStrings(t *testing.T) { a := []uint64{1, 2, 3, 4, 5} t.Log(a) t.Log(reflect.TypeOf(a).String()) b := ArrayStrings(a) t.Log(b) t.Log(reflect.TypeOf(b).String()) } type Tree struct { ID uint64 `json:"id"` Checked bool `json:"checked"` Children []*Tree `json:"children"` } func show(src []*Tree, parent *Tree) { for _, v := range src { if !v.Checked && parent != nil { parent.Checked = false } if len(v.Children) > 0 { show(v.Children, v) } } } func input(src []*Tree, out map[uint64]uint64) { for _, v := range src { out[v.ID] = v.ID if len(v.Children) > 0 { input(v.Children, out) } } } func TestInArray(t *testing.T) { src := []*Tree{ &Tree{ ID: 1, Checked: false, Children: []*Tree{ &Tree{ ID: 2, Checked: true, Children: nil, }, &Tree{ ID: 3, Checked: false, Children: nil, }, }, }, } out := make(map[uint64]uint64, 0) input(src, out) //show(out, nil) t.Log(AnyToJSON(out)) }