dfa_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package main
  2. import (
  3. "fmt"
  4. "runtime"
  5. "testing"
  6. "time"
  7. )
  8. func TestMultiTreeChinese(t *testing.T) {
  9. mt := NewMultiTree()
  10. words := []string{"芜湖市伍月服装有限公司", "芜湖东安建设工程咨询有限公司", "安徽帮扶教育科技集团有限公司", "芜湖爱菊营销策划有限公司", "安徽省无为县精诚电器有限责任公司",
  11. "芜湖通益建筑安装有限责任公司", "芜湖县糖烟酒日杂有限公司", "芜湖文晖商贸经营部", "芜湖市阪新服饰有限公司", "芜湖市尚居装饰设计工程有限公司", "安徽天江建设有限公司"}
  12. for _, word := range words {
  13. mt.Add(word)
  14. }
  15. results := mt.Match("芜湖文晖商贸经营部", true)
  16. fmt.Println(results)
  17. }
  18. func TestMonday(t *testing.T) {
  19. now := time.Now()
  20. // 获取当前时间的星期几(0表示周一,1表示周二,以此类推)
  21. weekday := now.Weekday()
  22. // 计算从周日到现在的天数(因为一周从周日开始,所以需要减一天)
  23. daysSinceSunday := int(weekday) - 1
  24. // 计算周一的时间
  25. monday := now.AddDate(0, 0, -daysSinceSunday)
  26. // 将时间格式化为凌晨(00:00:00)
  27. mondayAtMidnight := time.Date(monday.Year(), monday.Month(), monday.Day(), 0, 0, 0, 0, monday.Location())
  28. fmt.Println("aaa", mondayAtMidnight.Unix())
  29. fmt.Println("当前时间:", now.Format("2006-01-02 15:04:05 MST"))
  30. fmt.Println("本周周一凌晨时间:", mondayAtMidnight.Format("2006-01-02 15:04:05 MST"))
  31. }
  32. func TestNewMultiTree(t *testing.T) {
  33. for i := 0; i < 1000000; i++ {
  34. _ = make([]byte, 1024) // Allocate 1 Kb
  35. }
  36. TraceMemStats()
  37. // Explicitly trigger a garbage collection
  38. runtime.GC()
  39. TraceMemStats()
  40. // Sleep for a while to observe the changes in memory stats
  41. time.Sleep(time.Second * 2)
  42. TraceMemStats()
  43. }