Go语言单元测试
发布时间:2020-12-16 19:24:37 所属栏目:大数据 来源:网络整理
导读:package ceimport ("crypto/md5""math/rand")func getmd5(s []byte) []byte {md := md5.New()md.Write(s)x := md.Sum([]byte(""))return x}func T() string {name := rangdom_string()x := getmd5(name)if x[0] 127 {return "A"} else {return "B"}}func ran
package ce import ( "crypto/md5" "math/rand" ) func getmd5(s []byte) []byte { md := md5.New() md.Write(s) x := md.Sum([]byte("")) return x } func T() string { name := rangdom_string() x := getmd5(name) if x[0] > 127 { return "A" } else { return "B" } } func rangdom_string() []byte { var x []byte for i := 0; i < 10; i++ { a := rand.Intn(100) x = append(x,byte(a+33)) } return x } 测试文件必须是*_test.go结尾 package ce import "testing" func Test_getmd5(t *testing.T) { for i := 0; i < 1000000; i++ { T() } } func Benchmark_getmd5(b *testing.B) { for i := 0; i < b.N; i++ { T() } } func Test_Range(t *testing.T) { for i := 0; i < 1000000; i++ { rangdom_string() } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |