| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package utils
- import (
- "fmt"
- "github.com/shopspring/decimal"
- "testing"
- )
- func TestPeriodNo(t *testing.T) {
- // 获取当前期号
- currentPeriod := NowPeriodNo()
- fmt.Printf("当前期号: %s\n", currentPeriod)
- // 获取下一期
- nextPeriod := NextPeriodNoSimple("2025121602")
- fmt.Printf("下一期: %s\n", nextPeriod) // 输出: 2025121604
- nextPeriod2 := NextPeriodNoSimple("2025121622")
- fmt.Printf("跨天下一期: %s\n", nextPeriod2) // 输出: 2025121700
- // 跳转到指定期数
- jumpPeriod := JumpToPeriodNoSimple("2025123122", 6)
- fmt.Printf("跳转6期: %s\n", jumpPeriod) // 输出: 2025121614
- // 跨天跳转
- jumpPeriod2 := JumpToPeriodNoSimple("2025121622", 3)
- fmt.Printf("跨天跳转3期: %s\n", jumpPeriod2) // 输出: 2025121704
- spans := CalPeriodNosSpan("2025123122", "2026010110")
- fmt.Printf("跨期: %d\n", spans)
- }
- func TestToSnakeCase(t *testing.T) {
- t.Log(VarToSnakeCase(" helloWord"))
- t.Log(WordsToSnakeCase(" helloWord desc"))
- t.Log(WordsToSnakeCase(" password desc, HelloWord acs"))
- }
- func TestFormatLessZeroDecimal(t *testing.T) {
- t.Log(FormatDecimalToString(decimal.NewFromFloat(10001234.6798)))
- t.Log(FormatDecimalToString(decimal.NewFromFloat(11234.6798)))
- t.Log(FormatDecimalToString(decimal.NewFromFloat(0.12345)))
- t.Log(FormatDecimalToString(decimal.NewFromFloat(0.00005432383)))
- t.Log(FormatDecimalToString(decimal.NewFromFloat(0.000000985432383)))
- }
- func TestTrueRandomInt64Slice(t *testing.T) {
- var int64Slice = []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
- var randInt64List []int64
- for i := 0; i < 1000000; i++ {
- randInt64, err := TrueRandomInt64Slice(int64Slice)
- if err != nil {
- t.Log(err.Error())
- }
- randInt64List = append(randInt64List, randInt64)
- }
- //t.Log(randInt64List)
- countMap := make(map[int64]int)
- for _, num := range randInt64List {
- countMap[num]++
- }
- for num, count := range countMap {
- fmt.Printf("数字 %d: 出现 %d 次\n", num, count)
- }
- }
|