utils_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/shopspring/decimal"
  5. "testing"
  6. )
  7. func TestPeriodNo(t *testing.T) {
  8. // 获取当前期号
  9. currentPeriod := NowPeriodNo()
  10. fmt.Printf("当前期号: %s\n", currentPeriod)
  11. // 获取下一期
  12. nextPeriod := NextPeriodNoSimple("2025121602")
  13. fmt.Printf("下一期: %s\n", nextPeriod) // 输出: 2025121604
  14. nextPeriod2 := NextPeriodNoSimple("2025121622")
  15. fmt.Printf("跨天下一期: %s\n", nextPeriod2) // 输出: 2025121700
  16. // 跳转到指定期数
  17. jumpPeriod := JumpToPeriodNoSimple("2025123122", 6)
  18. fmt.Printf("跳转6期: %s\n", jumpPeriod) // 输出: 2025121614
  19. // 跨天跳转
  20. jumpPeriod2 := JumpToPeriodNoSimple("2025121622", 3)
  21. fmt.Printf("跨天跳转3期: %s\n", jumpPeriod2) // 输出: 2025121704
  22. spans := CalPeriodNosSpan("2025123122", "2026010110")
  23. fmt.Printf("跨期: %d\n", spans)
  24. }
  25. func TestToSnakeCase(t *testing.T) {
  26. t.Log(VarToSnakeCase(" helloWord"))
  27. t.Log(WordsToSnakeCase(" helloWord desc"))
  28. t.Log(WordsToSnakeCase(" password desc, HelloWord acs"))
  29. }
  30. func TestFormatLessZeroDecimal(t *testing.T) {
  31. t.Log(FormatDecimalToString(decimal.NewFromFloat(10001234.6798)))
  32. t.Log(FormatDecimalToString(decimal.NewFromFloat(11234.6798)))
  33. t.Log(FormatDecimalToString(decimal.NewFromFloat(0.12345)))
  34. t.Log(FormatDecimalToString(decimal.NewFromFloat(0.00005432383)))
  35. t.Log(FormatDecimalToString(decimal.NewFromFloat(0.000000985432383)))
  36. }
  37. func TestTrueRandomInt64Slice(t *testing.T) {
  38. var int64Slice = []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
  39. var randInt64List []int64
  40. for i := 0; i < 1000000; i++ {
  41. randInt64, err := TrueRandomInt64Slice(int64Slice)
  42. if err != nil {
  43. t.Log(err.Error())
  44. }
  45. randInt64List = append(randInt64List, randInt64)
  46. }
  47. //t.Log(randInt64List)
  48. countMap := make(map[int64]int)
  49. for _, num := range randInt64List {
  50. countMap[num]++
  51. }
  52. for num, count := range countMap {
  53. fmt.Printf("数字 %d: 出现 %d 次\n", num, count)
  54. }
  55. }