163 lines
3.2 KiB
Go
163 lines
3.2 KiB
Go
package test
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"testing"
|
|
|
|
"legu.airobot/busi/friend"
|
|
"legu.airobot/lib"
|
|
"legu.airobot/storage"
|
|
)
|
|
|
|
func TestAction(t *testing.T) {
|
|
aip := lib.AIParam{}
|
|
ai, _ := lib.NewAI(aip)
|
|
|
|
// 创建场景
|
|
scene := lib.NewScene(ai, lib.SceneParam{
|
|
Name: "场景1",
|
|
Desc: "好友",
|
|
})
|
|
|
|
//为场景选择caller
|
|
scene.AddCaller(&friend.FriendRecommend{})
|
|
|
|
//加机器人
|
|
// ai.AddRobot(scene)
|
|
|
|
//运行机器人
|
|
// for _, v := range ai.GetRobots("场景1") {
|
|
// v.Start()
|
|
// }
|
|
|
|
}
|
|
|
|
func TestA(t *testing.T) {
|
|
|
|
q := lib.NewQueue[int]()
|
|
q.Add(1)
|
|
q.Add(2)
|
|
|
|
// list := q.List()
|
|
for {
|
|
i, err := q.Pop()
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
fmt.Println(i)
|
|
}
|
|
}
|
|
|
|
func TestMerge(t *testing.T) {
|
|
config := &storage.Config{
|
|
Global: &storage.Global{UserCountTotal: 2, SId: "dfz", UserCount: 1},
|
|
}
|
|
ma, _ := lib.NewAI(lib.AIParam{Config: config})
|
|
|
|
robot1 := lib.NewRobot(ma)
|
|
robot1.ReportMap = make(map[int]map[string]*lib.Statistics)
|
|
robot1.ReportMap[1] = make(map[string]*lib.Statistics)
|
|
robot1.ReportMap[1]["user.login"] = &lib.Statistics{
|
|
ElapseTotal: 5,
|
|
CallCount: 2,
|
|
AvgElapse: 2,
|
|
MaxElapse: 4,
|
|
MinElapse: 2,
|
|
Route: "user.login",
|
|
SceneName: "登录",
|
|
}
|
|
ma.AppendRobot(robot1)
|
|
///////////////
|
|
robot2 := lib.NewRobot(ma)
|
|
robot2.ReportMap = make(map[int]map[string]*lib.Statistics)
|
|
robot2.ReportMap[1] = make(map[string]*lib.Statistics)
|
|
robot2.ReportMap[1]["user.login"] = &lib.Statistics{
|
|
ElapseTotal: 7,
|
|
CallCount: 1,
|
|
AvgElapse: 3,
|
|
MaxElapse: 5,
|
|
MinElapse: 4,
|
|
Route: "user.login",
|
|
SceneName: "登录",
|
|
}
|
|
ma.AppendRobot(robot2)
|
|
//////
|
|
robot3 := lib.NewRobot(ma)
|
|
robot3.ReportMap = make(map[int]map[string]*lib.Statistics)
|
|
robot3.ReportMap[1] = make(map[string]*lib.Statistics)
|
|
robot3.ReportMap[1]["user.login"] = &lib.Statistics{
|
|
ElapseTotal: 8,
|
|
CallCount: 1,
|
|
AvgElapse: 2,
|
|
MaxElapse: 6,
|
|
MinElapse: 3,
|
|
Route: "user.login",
|
|
SceneName: "登录",
|
|
}
|
|
ma.AppendRobot(robot3)
|
|
ma.MergeResult()
|
|
|
|
robot4 := lib.NewRobot(ma)
|
|
robot4.ReportMap = make(map[int]map[string]*lib.Statistics)
|
|
robot4.ReportMap[1] = make(map[string]*lib.Statistics)
|
|
robot4.ReportMap[1]["user.login"] = &lib.Statistics{
|
|
ElapseTotal: 8,
|
|
CallCount: 1,
|
|
AvgElapse: 2,
|
|
MaxElapse: 8,
|
|
MinElapse: 2,
|
|
Route: "user.login",
|
|
SceneName: "登录",
|
|
}
|
|
ma.AppendRobot(robot4)
|
|
ma.MergeResult()
|
|
|
|
fmt.Println(ma.ReportMap)
|
|
for i, v := range ma.ReportMap {
|
|
fmt.Println(i)
|
|
for j, m := range v {
|
|
fmt.Printf("【%s】 调用次数:%v 总耗时:%v 平均:%v 最大:%v 最小:%v\n", j, m.CallCount, m.ElapseTotal, m.AvgElapse, m.MaxElapse, m.MinElapse)
|
|
}
|
|
}
|
|
}
|
|
func divide(a int, b int) int {
|
|
if a == math.MinInt32 && b == -1 {
|
|
return math.MaxInt32
|
|
}
|
|
var sign = 1
|
|
if a > 0 && b < 0 || a < 0 && b > 0 {
|
|
sign = -1
|
|
}
|
|
if a < 0 {
|
|
a = -a
|
|
}
|
|
if b < 0 {
|
|
b = -b
|
|
}
|
|
var res int64
|
|
for {
|
|
if a < b {
|
|
break
|
|
}
|
|
// a< b ,res = 0
|
|
var cur = 1
|
|
var temp = b
|
|
for temp+temp <= a {
|
|
temp += temp
|
|
cur += cur
|
|
}
|
|
res += int64(cur)
|
|
a -= temp
|
|
}
|
|
return int(res * int64(sign))
|
|
|
|
}
|
|
|
|
func TestDiv(t *testing.T) {
|
|
|
|
res := lib.FormatFloatCommon(float64(3 / 10))
|
|
fmt.Println(res)
|
|
}
|