-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_string_test.go
More file actions
53 lines (45 loc) · 1.28 KB
/
random_string_test.go
File metadata and controls
53 lines (45 loc) · 1.28 KB
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
package utils_test
import (
"math"
"testing"
"github.com/loickreitmann/utils"
)
func TestUtils_RandomString(t *testing.T) {
// ARRANGE
var testUtils utils.Utils
expectedLens := []int{-23, 0, 1, 5, 7, 22, 36, 789, 10000}
actualLens := []int{}
// ACT
for i := range expectedLens {
str := testUtils.RandomString(expectedLens[i])
actualLens = append(actualLens, len(str))
}
// ASSERT
for i := range actualLens {
if actualLens[i] != int(math.Abs(float64(expectedLens[i]))) {
t.Errorf("wrong string length; expected %d, got %d", expectedLens[i], actualLens[i])
}
}
}
func TestUtils_RandomString_CustomeSeed(t *testing.T) {
// ARRANGE
var testUtils utils.Utils
expectedLens := []int{-23, 0, 1, 5, 7, 314}
actualStrs := []string{}
customSeed := []rune("ou812")
// ACT
for i := range expectedLens {
str := testUtils.RandomString(expectedLens[i], customSeed)
actualStrs = append(actualStrs, str)
}
// ASSERT
for i := range actualStrs {
if len(actualStrs[i]) != int(math.Abs(float64(expectedLens[i]))) {
t.Errorf("wrong string length; expected %d, got %d", expectedLens[i], len(actualStrs[i]))
}
uniqs := testUtils.UniqueRunes(actualStrs[i])
if !testUtils.ContainsAllRunes(customSeed, uniqs) {
t.Error("characters found in string not contained i seed set")
}
}
}