-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_test.go
52 lines (40 loc) · 1023 Bytes
/
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
package gouse
import (
"reflect"
"testing"
)
func TestRandNum(t *testing.T) {
min := 1
max := 10
result := RandNum(min, max)
if result < min || result > max {
t.Errorf("Random() = %d; want >= %d and <= %d", result, min, max)
}
}
func BenchmarkRandNum(b *testing.B) {
min := 1
max := 10
for i := 0; i < b.N; i++ {
RandNum(min, max)
}
}
func TestRandStr(t *testing.T) {
expectedLength := 10
got := RandStr(expectedLength)
if len(got) != expectedLength {
t.Errorf("RandomStr() = %v, want %v", len(got), expectedLength)
}
if reflect.TypeOf(got).Kind() != reflect.String {
t.Errorf("RandomStr() = %v, want %v", reflect.TypeOf(got).Kind(), reflect.String)
}
}
func TestRandDigit(t *testing.T) {
expectedLength := 6
got := RandDigit(expectedLength)
if len(got) != expectedLength {
t.Errorf("RandomNum() = %v, want %v", len(got), expectedLength)
}
if reflect.TypeOf(got).Kind() != reflect.String {
t.Errorf("RandomNum() = %v, want %v", reflect.TypeOf(got).Kind(), reflect.String)
}
}