-
Notifications
You must be signed in to change notification settings - Fork 1
/
random_test.go
55 lines (46 loc) · 1.03 KB
/
random_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**********************************************************
* Author :
* Email :
* Last modified : 2016-09-15 17:29:51
* Filename : random.go
* Description : 常用的随机数工具方法
* *******************************************************/
package utils
import (
"reflect"
"testing"
)
func TestRand_01(t *testing.T) {
bs0 := RandomCreateBytes(16)
bs1 := RandomCreateBytes(16)
t.Log(string(bs0), string(bs1))
if string(bs0) == string(bs1) {
t.FailNow()
}
bs0 = RandomCreateBytes(4, []byte(`a`)...)
if string(bs0) != "aaaa" {
t.FailNow()
}
}
func TestRand_02(t *testing.T) {
bs0 := RandInt()
bs1 := RandIntN(16)
t.Log(bs0, bs1)
if reflect.ValueOf(bs0).Kind() != reflect.Int {
t.FailNow()
}
if reflect.ValueOf(bs1).Kind() != reflect.Int {
t.FailNow()
}
}
func TestRand_03(t *testing.T) {
bs0 := RandFloat32()
bs1 := RandFloat64()
t.Log(bs0, bs1)
if reflect.ValueOf(bs0).Kind() != reflect.Float32 {
t.FailNow()
}
if reflect.ValueOf(bs1).Kind() != reflect.Float64 {
t.FailNow()
}
}