Files
cas_tt_cloud_backend/utils/array_test.go

94 lines
1.4 KiB
Go
Raw Normal View History

2021-09-28 11:47:19 +08:00
package utils
import (
2022-03-05 15:31:22 +08:00
"math"
2021-09-28 11:47:19 +08:00
"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)
2022-01-24 11:28:21 +08:00
//d := a & b & c
//t.Log(d)
2021-09-28 11:47:19 +08:00
2022-03-05 15:31:22 +08:00
//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))
2021-09-28 11:47:19 +08:00
}
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())
}
2022-01-04 11:59:58 +08:00
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))
}