-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniq_test.go
44 lines (35 loc) · 888 Bytes
/
uniq_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
package uniq
import (
"math/rand"
"testing"
"time"
)
func TestGenerateRandomStringWithUpperCase(t *testing.T) {
seed := rand.New(rand.NewSource(time.Now().UnixNano()))
tests := []struct {
length int
numUpperCase int
}{
{10, 3},
{15, 5},
{20, 7},
{30, 12},
{50, 20},
}
for _, tt := range tests {
result := generateRandomStringWithUpperCase(seed, tt.length, tt.numUpperCase)
t.Log(result, tt.length, len(result))
if len(result) != tt.length {
t.Errorf("Generated string %s length is incorrect. Expected: %d, Got: %d", result, tt.length, len(result))
}
numUpperCase := 0
for _, char := range result {
if char >= 'A' && char <= 'Z' {
numUpperCase++
}
}
if numUpperCase != tt.numUpperCase {
t.Errorf("Number of uppercase in %s characters is incorrect. Expected: %d, Got: %d", result, tt.numUpperCase, numUpperCase)
}
}
}