pet-house/business/utils/commonUtil_test.go

76 lines
1.6 KiB
Go

package utils
import (
"fmt"
"math"
"pet-house.com/business/models"
"strconv"
"testing"
"time"
)
func TestGetStrDays(t *testing.T) {
var ReserveMap map[string]models.ReserveTimeFilter
ReserveMap = make(map[string]models.ReserveTimeFilter)
ReserveMap["2024-04-10"] = models.ReserveTimeFilter{
Type: 1,
Content: "2024-04-10",
}
ReserveMap["12"] = models.ReserveTimeFilter{
Type: 2,
Content: "12",
}
//days := GetStrDays(7, 30, ReserveMap, nil, 1, nil, 2)
//fmt.Println(days)
}
func TestCalc(t *testing.T) {
i := math.Round(386 * (float64(85) / 100))
fmt.Println(i)
}
func TestCalc1(t *testing.T) {
i := float64(85) / 100
fmt.Println(i)
}
func roundToOneDecimalPlace(value float64) float64 {
return math.Round(value*10) / 10
}
func TestCalc3(t *testing.T) {
i := float64(348) * 0.95
fmt.Println(i)
}
func TestCalc4(t *testing.T) {
value := 267.77
roundedValue := roundToOneDecimalPlace(value)
fmt.Printf("%.1f\n", roundedValue) // 输出 3.1
}
func TestCalc5(t *testing.T) {
var a = 1596
float := strconv.FormatFloat(float64(a/10.0), 'f', 1, 64)
fmt.Printf(float)
}
func TestMath(t *testing.T) {
var a = int(RoundToOneDecimalPlace(float64(150)*(95/100.0)) * 10)
fmt.Println(a)
}
func TestMap(t *testing.T) {
var c1 = make(map[int]models.Coupons)
c1[1] = models.Coupons{
Id: 1,
Name: "111",
GoodsSubType: 0,
Discount: 0,
Source: "",
PeriodType: 0,
Period: "",
PeriodInfo: nil,
ExpireTime: 0,
CreateTime: time.Time{},
UpdateTime: time.Time{},
Status: 0,
}
print("12345", c1[2].Id)
}