go_dreamfactory/utils/utils_test.go
2022-11-02 19:54:53 +08:00

78 lines
1.2 KiB
Go

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.RandomNumbers(0, 99, 10))
}
}
func BenchmarkNumber(b *testing.B) {
b.Log("begin")
b.ReportAllocs()
for i := 0; i < b.N; i++ {
utils.RandomNumbers(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")
}