package common

import (
	"fmt"
	"go_dreamfactory/pb"
	"reflect"
	"strconv"
	"testing"
	"time"
)

func TestSubStr(t *testing.T) {
	str := "type.googleapis.com/UserResChangePush"
	r := SubStr(str, 20, len(str))
	fmt.Println(r)
}

func TestConver(t *testing.T) {

	s := ConvertFileSize(25325466)
	fmt.Println(s)
}

func TestIsUpgrade(t *testing.T) {
	IsUpgrade("1.2.2", "1.0.21")
}

func TestJsonToPb(t *testing.T) {
	jsonStr := `{"account":"zhaocy","sid":"dfz"}`
	login := &pb.UserLoginReq{}
	Json2Pb(jsonStr, login)
	fmt.Println(login.Account, login.Sid)

	fmt.Println(Pb2Json(login))

	t2 := reflect.TypeOf(login)
	fmt.Println("Name:", t2.Elem().Name())
}

func TestSpli(t *testing.T) {
	now := time.Now()
	fmt.Println(now.UnixNano())
	fmt.Println(now.UnixNano() / 1e6) //将纳秒转换为毫秒
}

func TestDiv(t *testing.T) {
	numF := float64(32766600)
	// 保留两位小数, 通用
	value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", numF/1e6), 64)
	fmt.Println(reflect.TypeOf(value), value)
	fmt.Println(FormatFloatCommon(numF / 1e6))

	num, _ := FormatFloat(numF, 2)
	fmt.Println(reflect.TypeOf(num), num)
	// 舍弃的尾数不为0，强制进位
	num, _ = FormatFloatCeil(0.2205, 2)
	fmt.Println(reflect.TypeOf(num), num)
	// 强制舍弃尾数
	num, _ = FormatFloatFloor(0.2295, 2)
	fmt.Println(reflect.TypeOf(num), num)
}

func TestSub(t *testing.T){
	fmt.Println(LastChars("23af2", 6))
}