go_dreamfactory/utils/utils_test.go
2022-11-17 20:33:44 +08:00

90 lines
1.5 KiB
Go

package utils_test
import (
"fmt"
"go_dreamfactory/sys/configure"
"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(configure.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")
}
func TestCompre(t *testing.T){
a:=[]int32{1,2,4,5}
b:=[]int32{1,2,4}
fmt.Println(utils.ForContainer(a,b))
}
func TestDeletex(t *testing.T){
a:=[]int32{1,2,3,4}
c:=utils.Deletex(a, 2)
fmt.Println(c)
}