package utils_test import ( "fmt" "go_dreamfactory/utils" "strconv" "testing" "time" . "github.com/smartystreets/goconvey/convey" "github.com/spf13/cast" ) func TestIsToday(t *testing.T) { // fmt.Println(utils.IsToday(0)) tt := time.Unix(1658139742, 0) fmt.Println(time.Now().Before(tt)) } func TestIsYestoday(t *testing.T) { Convey("昨天", t, func() { b := utils.IsYestoday(1661912369) So(b, ShouldEqual, true) }) } func TestSubTime(t *testing.T) { fmt.Println(utils.IsAfterWeek(1657172915)) } func TestRandom(t *testing.T) { fmt.Println(utils.GenValidateCode(6)) } func TestNumber(t *testing.T) { for i := 0; i < 100; i++ { fmt.Println(utils.Numbers(0, 99, 10)) } } func BenchmarkNumber(b *testing.B) { b.Log("begin") b.ReportAllocs() for i := 0; i < b.N; i++ { utils.Numbers(0, 1000, 10) } } func BenchmarkStringToInt32(b *testing.B) { b.Log("begin") b.ReportAllocs() for i := 0; i < b.N; i++ { a := "123123" strconv.Atoi(a) // cast.ToInt32(a) } } func BenchmarkInt32ToString(b *testing.B) { b.Log("begin") b.ReportAllocs() for i := 0; i < b.N; i++ { a := 123123 // strconv.Itoa(a) cast.ToString(a) } } func TestMatrxing(t *testing.T) { utils.MatrixingHour("2022-10-11 00:00:00") }