package curl2info import ( "fmt" "runtime" "testing" "time" ) // type LRValue struct { // left, right int // } func TestParseCrontab(t *testing.T) { // crontab := "0-5/2,7-30/3,30,35,40-^1 * * * *" //(秒) 分 时 号(每月的多少号, 要注意月可可能性) 星期几(每个星期的) /每 ,列表 -范围 crontab := "* * * * *" PrintMemUsage() ty := newTrieYear() cron := NewCrontab(crontab) ty.FromCrontab(cron) if len(ty.GetPlanTime(cron, time.Now(), 10)) != 10 { t.Error("GetPlanTime error len != 10") } cron.createYearPlan() if !cron.TimeUp() { t.Error("timeup error") } PrintMemUsage() } func TestParseInterval(t *testing.T) { // crontab := "0-5/2,7-30/3,30,35,40-^1 * * * *" //(秒) 分 时 号(每月的多少号, 要注意月可可能性) 星期几(每个星期的) /每 ,列表 -范围 // t.Error("") // crontab := "f1-2|1-3|5-8x5,f1|10m,10-15,f1" // PrintMemUsage() // cron := NewCrontab(crontab) // now := time.Now() // for i := 0; i <= 15; i++ { // if cron.TimeUp() { // log.Println(time.Since(now)) // now = time.Now() // } // time.Sleep(time.Second) // } // PrintMemUsage() } func TestCrontabPlus(t *testing.T) { // crontab := "0-5/2,7-30/3,30,35,40-^1 * * * *" //(秒) 分 时 号(每月的多少号, 要注意月可可能性) 星期几(每个星期的) /每 ,列表 -范围 // crondata := NewCrontab("*22 * * * *") } func PrintMemUsage() { var m runtime.MemStats runtime.ReadMemStats(&m) // For info on each, see: https://golang.org/pkg/runtime/#MemStats fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc)) fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc)) fmt.Printf("\tSys = %v MiB", bToMb(m.Sys)) fmt.Printf("\tNumGC = %v\n", m.NumGC) } func bToMb(b uint64) uint64 { return b / 1024 / 1024 }