|
|
package utils
import ( "fmt" "github.com/shopspring/decimal" . "github.com/smartystreets/goconvey/convey" "testing" )
func TestQrcode2Base64(t *testing.T) { Convey("测试生成二维码并把二维码变成base64编码", t, func() { urlPath := "https://www.baidu.com" code, err := Qrcode2Base64(urlPath) So(err, ShouldBeNil) So(code, ShouldStartWith, "data:image/png;base64,") }) }
func TestFloat64CusDecimal(t *testing.T) { Convey("测试把float64精度截断", t, func() { f1 := 2000.22202 f := Float64CusDecimal(f1, 2) So(f, ShouldEqual, 2000.22) f2 := 5000.4 f = Float64CusDecimal(f2, 1) So(f, ShouldEqual, f2) f3 := 5000.509 f = Float64CusDecimal(f3, 2) So(f, ShouldNotEqual, 5000.50) }) }
func TestGif2Base64(t *testing.T) { Convey("测试把gif编码为base64", t, func() { urlPath := "http://photocdn.sohu.com/20150721/mp23627612_1437451852870_2.gif" gif, err := Gif2Base64(urlPath) So(err, ShouldEqual, nil) So(gif, ShouldStartWith, "data:image/gif;base64")
urlPath = "https://www.baidu.com" gif, err = Gif2Base64(urlPath) So(err, ShouldBeNil) So(urlPath, ShouldEqual, urlPath)
urlPath = "xxxx.gif" gif, err = Gif2Base64(urlPath) So(err, ShouldNotEqual, nil) }) }
func TestPathExists(t *testing.T) { Convey("测试文件是否存在", t, func() { // 存在状态
path := "utils.go" exist, err := PathExists(path) So(err, ShouldEqual, nil) So(exist, ShouldBeTrue) // 不存在状态
path = "utils.+" exist, err = PathExists(path) So(err, ShouldBeNil) So(exist, ShouldBeFalse) }) }
func TestCountDownFormat(t *testing.T) { //Convey("测试倒计时格式", t, func() {
// //num := 12000
// //str := CountDownFormat(num)
// //So(str, ShouldEqual, "3:20:0")
//})
d, _ := decimal.NewFromString("-123.45") d2, _ := decimal.NewFromString(".0001") a := d.Add(d2) fmt.Println(a.Float64())
}
|