@@ -5,82 +5,82 @@ import test from 'ava'
5
5
6
6
test ( 'Char Set Base 64 Strings' , t => {
7
7
let random = new Random ( charSet64 )
8
- t . is ( random . stringWithBytes ( 6 , Buffer . from ( [ 0xdd ] ) ) , '3' )
9
- t . is ( random . stringWithBytes ( 12 , Buffer . from ( [ 0x78 , 0xfc ] ) ) , 'eP' )
10
- t . is ( random . stringWithBytes ( 18 , Buffer . from ( [ 0xc5 , 0x6f , 0x21 ] ) ) , 'xW8' )
11
- t . is ( random . stringWithBytes ( 24 , Buffer . from ( [ 0xc9 , 0x68 , 0xc7 ] ) ) , 'yWjH' )
12
- t . is ( random . stringWithBytes ( 30 , Buffer . from ( [ 0xa5 , 0x62 , 0x20 , 0x87 ] ) ) , 'pWIgh' )
13
- t . is ( random . stringWithBytes ( 36 , Buffer . from ( [ 0x39 , 0x51 , 0xca , 0xcc , 0x8b ] ) ) , 'OVHKzI' )
14
- t . is ( random . stringWithBytes ( 42 , Buffer . from ( [ 0x83 , 0x89 , 0x00 , 0xc7 , 0xf4 , 0x02 ] ) ) , 'g4kAx_Q' )
15
- t . is ( random . stringWithBytes ( 48 , Buffer . from ( [ 0x51 , 0xbc , 0xa8 , 0xc7 , 0xc9 , 0x17 ] ) ) , 'Ubyox8kX' )
16
- t . is ( random . stringWithBytes ( 54 , Buffer . from ( [ 0xd2 , 0xe3 , 0xe9 , 0xda , 0x19 , 0x97 , 0x52 ] ) ) , '0uPp2hmXU' )
8
+ t . is ( random . stringWithBytes ( 6 , [ 0xdd ] ) , '3' )
9
+ t . is ( random . stringWithBytes ( 12 , [ 0x78 , 0xfc ] ) , 'eP' )
10
+ t . is ( random . stringWithBytes ( 18 , [ 0xc5 , 0x6f , 0x21 ] ) , 'xW8' )
11
+ t . is ( random . stringWithBytes ( 24 , [ 0xc9 , 0x68 , 0xc7 ] ) , 'yWjH' )
12
+ t . is ( random . stringWithBytes ( 30 , [ 0xa5 , 0x62 , 0x20 , 0x87 ] ) , 'pWIgh' )
13
+ t . is ( random . stringWithBytes ( 36 , [ 0x39 , 0x51 , 0xca , 0xcc , 0x8b ] ) , 'OVHKzI' )
14
+ t . is ( random . stringWithBytes ( 42 , [ 0x83 , 0x89 , 0x00 , 0xc7 , 0xf4 , 0x02 ] ) , 'g4kAx_Q' )
15
+ t . is ( random . stringWithBytes ( 48 , [ 0x51 , 0xbc , 0xa8 , 0xc7 , 0xc9 , 0x17 ] ) , 'Ubyox8kX' )
16
+ t . is ( random . stringWithBytes ( 54 , [ 0xd2 , 0xe3 , 0xe9 , 0xda , 0x19 , 0x97 , 0x52 ] ) , '0uPp2hmXU' )
17
17
t . is ( random . stringWithBytes ( 60 , [ 0xd9 , 0x39 , 0xc1 , 0xaf , 0x1e , 0x2e , 0x69 , 0x48 ] ) , '2TnBrx4uaU' )
18
- t . is ( random . stringWithBytes ( 66 , Buffer . from ( [ 0x78 , 0x3f , 0xfd , 0x93 , 0xd1 , 0x06 , 0x90 , 0x4b , 0xd6 ] ) ) , 'eD_9k9EGkEv' )
19
- t . is ( random . stringWithBytes ( 72 , Buffer . from ( [ 0x9d , 0x99 , 0x4e , 0xa5 , 0xd2 , 0x3f , 0x8c , 0x86 , 0x80 ] ) ) , 'nZlOpdI_jIaA' )
18
+ t . is ( random . stringWithBytes ( 66 , [ 0x78 , 0x3f , 0xfd , 0x93 , 0xd1 , 0x06 , 0x90 , 0x4b , 0xd6 ] ) , 'eD_9k9EGkEv' )
19
+ t . is ( random . stringWithBytes ( 72 , [ 0x9d , 0x99 , 0x4e , 0xa5 , 0xd2 , 0x3f , 0x8c , 0x86 , 0x80 ] ) , 'nZlOpdI_jIaA' )
20
20
} )
21
21
22
22
test ( 'Char Set Base 32 Strings' , t => {
23
23
let random = new Random ( charSet32 )
24
- t . is ( random . stringWithBytes ( 5 , Buffer . from ( [ 0xdd ] ) ) , 'N' )
25
- t . is ( random . stringWithBytes ( 10 , Buffer . from ( [ 0x78 , 0xfc ] ) ) , 'p6' )
26
- t . is ( random . stringWithBytes ( 15 , Buffer . from ( [ 0x78 , 0xfc ] ) ) , 'p6R' )
27
- t . is ( random . stringWithBytes ( 20 , Buffer . from ( [ 0xc5 , 0x6f , 0x21 ] ) ) , 'JFHt' )
28
- t . is ( random . stringWithBytes ( 25 , Buffer . from ( [ 0xa5 , 0x62 , 0x20 , 0x87 ] ) ) , 'DFr43' )
29
- t . is ( random . stringWithBytes ( 30 , Buffer . from ( [ 0xa5 , 0x62 , 0x20 , 0x87 ] ) ) , 'DFr433' )
30
- t . is ( random . stringWithBytes ( 35 , Buffer . from ( [ 0x39 , 0x51 , 0xca , 0xcc , 0x8b ] ) ) , 'b8dPFB7' )
31
- t . is ( random . stringWithBytes ( 40 , Buffer . from ( [ 0x39 , 0x51 , 0xca , 0xcc , 0x8b ] ) ) , 'b8dPFB7h' )
32
- t . is ( random . stringWithBytes ( 45 , Buffer . from ( [ 0x83 , 0x89 , 0x00 , 0xc7 , 0xf4 , 0x02 ] ) ) , 'qn7q3rTD2' )
33
- t . is ( random . stringWithBytes ( 50 , Buffer . from ( [ 0xd2 , 0xe3 , 0xe9 , 0xda , 0x19 , 0x97 , 0x52 ] ) ) , 'MhrRBGqLtQ' )
34
- t . is ( random . stringWithBytes ( 55 , Buffer . from ( [ 0xd2 , 0xe3 , 0xe9 , 0xda , 0x19 , 0x97 , 0x52 ] ) ) , 'MhrRBGqLtQf' )
24
+ t . is ( random . stringWithBytes ( 5 , [ 0xdd ] ) , 'N' )
25
+ t . is ( random . stringWithBytes ( 10 , [ 0x78 , 0xfc ] ) , 'p6' )
26
+ t . is ( random . stringWithBytes ( 15 , [ 0x78 , 0xfc ] ) , 'p6R' )
27
+ t . is ( random . stringWithBytes ( 20 , [ 0xc5 , 0x6f , 0x21 ] ) , 'JFHt' )
28
+ t . is ( random . stringWithBytes ( 25 , [ 0xa5 , 0x62 , 0x20 , 0x87 ] ) , 'DFr43' )
29
+ t . is ( random . stringWithBytes ( 30 , [ 0xa5 , 0x62 , 0x20 , 0x87 ] ) , 'DFr433' )
30
+ t . is ( random . stringWithBytes ( 35 , [ 0x39 , 0x51 , 0xca , 0xcc , 0x8b ] ) , 'b8dPFB7' )
31
+ t . is ( random . stringWithBytes ( 40 , [ 0x39 , 0x51 , 0xca , 0xcc , 0x8b ] ) , 'b8dPFB7h' )
32
+ t . is ( random . stringWithBytes ( 45 , [ 0x83 , 0x89 , 0x00 , 0xc7 , 0xf4 , 0x02 ] ) , 'qn7q3rTD2' )
33
+ t . is ( random . stringWithBytes ( 50 , [ 0xd2 , 0xe3 , 0xe9 , 0xda , 0x19 , 0x97 , 0x52 ] ) , 'MhrRBGqLtQ' )
34
+ t . is ( random . stringWithBytes ( 55 , [ 0xd2 , 0xe3 , 0xe9 , 0xda , 0x19 , 0x97 , 0x52 ] ) , 'MhrRBGqLtQf' )
35
35
} )
36
36
37
37
test ( 'Char Set Base 16 Strings' , t => {
38
38
let random = new Random ( charSet16 )
39
- t . is ( random . stringWithBytes ( 4 , Buffer . from ( [ 0x9d ] ) ) , '9' )
40
- t . is ( random . stringWithBytes ( 8 , Buffer . from ( [ 0xae ] ) ) , 'ae' )
41
- t . is ( random . stringWithBytes ( 12 , Buffer . from ( [ 0x01 , 0xf2 ] ) ) , '01f' )
42
- t . is ( random . stringWithBytes ( 16 , Buffer . from ( [ 0xc7 , 0xc9 ] ) ) , 'c7c9' )
43
- t . is ( random . stringWithBytes ( 20 , Buffer . from ( [ 0xc7 , 0xc9 , 0x00 ] ) ) , 'c7c90' )
39
+ t . is ( random . stringWithBytes ( 4 , [ 0x9d ] ) , '9' )
40
+ t . is ( random . stringWithBytes ( 8 , [ 0xae ] ) , 'ae' )
41
+ t . is ( random . stringWithBytes ( 12 , [ 0x01 , 0xf2 ] ) , '01f' )
42
+ t . is ( random . stringWithBytes ( 16 , [ 0xc7 , 0xc9 ] ) , 'c7c9' )
43
+ t . is ( random . stringWithBytes ( 20 , [ 0xc7 , 0xc9 , 0x00 ] ) , 'c7c90' )
44
44
} )
45
45
46
46
test ( 'Char Set Base 8 Strings' , t => {
47
47
let random = new Random ( charSet8 )
48
- t . is ( random . stringWithBytes ( 3 , Buffer . from ( [ 0x5a ] ) ) , '2' )
49
- t . is ( random . stringWithBytes ( 6 , Buffer . from ( [ 0x5a ] ) ) , '26' )
50
- t . is ( random . stringWithBytes ( 9 , Buffer . from ( [ 0x21 , 0xa4 ] ) ) , '103' )
51
- t . is ( random . stringWithBytes ( 12 , Buffer . from ( [ 0x21 , 0xa4 ] ) ) , '1032' )
52
- t . is ( random . stringWithBytes ( 15 , Buffer . from ( [ 0xda , 0x19 ] ) ) , '66414' )
53
- t . is ( random . stringWithBytes ( 18 , Buffer . from ( [ 0xfd , 0x93 , 0xd1 ] ) ) , '773117' )
54
- t . is ( random . stringWithBytes ( 21 , Buffer . from ( [ 0xfd , 0x93 , 0xd1 ] ) ) , '7731172' )
55
- t . is ( random . stringWithBytes ( 24 , Buffer . from ( [ 0xfd , 0x93 , 0xd1 ] ) ) , '77311721' )
56
- t . is ( random . stringWithBytes ( 27 , Buffer . from ( [ 0xc7 , 0xc9 , 0x07 , 0xc9 ] ) ) , '617444076' )
57
- t . is ( random . stringWithBytes ( 30 , Buffer . from ( [ 0xc7 , 0xc9 , 0x07 , 0xc9 ] ) ) , '6174440762' )
48
+ t . is ( random . stringWithBytes ( 3 , [ 0x5a ] ) , '2' )
49
+ t . is ( random . stringWithBytes ( 6 , [ 0x5a ] ) , '26' )
50
+ t . is ( random . stringWithBytes ( 9 , [ 0x21 , 0xa4 ] ) , '103' )
51
+ t . is ( random . stringWithBytes ( 12 , [ 0x21 , 0xa4 ] ) , '1032' )
52
+ t . is ( random . stringWithBytes ( 15 , [ 0xda , 0x19 ] ) , '66414' )
53
+ t . is ( random . stringWithBytes ( 18 , [ 0xfd , 0x93 , 0xd1 ] ) , '773117' )
54
+ t . is ( random . stringWithBytes ( 21 , [ 0xfd , 0x93 , 0xd1 ] ) , '7731172' )
55
+ t . is ( random . stringWithBytes ( 24 , [ 0xfd , 0x93 , 0xd1 ] ) , '77311721' )
56
+ t . is ( random . stringWithBytes ( 27 , [ 0xc7 , 0xc9 , 0x07 , 0xc9 ] ) , '617444076' )
57
+ t . is ( random . stringWithBytes ( 30 , [ 0xc7 , 0xc9 , 0x07 , 0xc9 ] ) , '6174440762' )
58
58
} )
59
59
60
60
test ( 'Char Set Base 4 Strings' , t => {
61
61
let random = new Random ( charSet4 )
62
- t . is ( random . stringWithBytes ( 2 , Buffer . from ( [ 0x5a ] ) ) , 'T' )
63
- t . is ( random . stringWithBytes ( 4 , Buffer . from ( [ 0x5a ] ) ) , 'TT' )
64
- t . is ( random . stringWithBytes ( 6 , Buffer . from ( [ 0x93 ] ) ) , 'CTA' )
65
- t . is ( random . stringWithBytes ( 8 , Buffer . from ( [ 0x93 ] ) ) , 'CTAG' )
66
- t . is ( random . stringWithBytes ( 10 , Buffer . from ( [ 0x20 , 0xf1 ] ) ) , 'ACAAG' )
67
- t . is ( random . stringWithBytes ( 12 , Buffer . from ( [ 0x20 , 0xf1 ] ) ) , 'ACAAGG' )
68
- t . is ( random . stringWithBytes ( 14 , Buffer . from ( [ 0x20 , 0xf1 ] ) ) , 'ACAAGGA' )
69
- t . is ( random . stringWithBytes ( 16 , Buffer . from ( [ 0x20 , 0xf1 ] ) ) , 'ACAAGGAT' )
62
+ t . is ( random . stringWithBytes ( 2 , [ 0x5a ] ) , 'T' )
63
+ t . is ( random . stringWithBytes ( 4 , [ 0x5a ] ) , 'TT' )
64
+ t . is ( random . stringWithBytes ( 6 , [ 0x93 ] ) , 'CTA' )
65
+ t . is ( random . stringWithBytes ( 8 , [ 0x93 ] ) , 'CTAG' )
66
+ t . is ( random . stringWithBytes ( 10 , [ 0x20 , 0xf1 ] ) , 'ACAAG' )
67
+ t . is ( random . stringWithBytes ( 12 , [ 0x20 , 0xf1 ] ) , 'ACAAGG' )
68
+ t . is ( random . stringWithBytes ( 14 , [ 0x20 , 0xf1 ] ) , 'ACAAGGA' )
69
+ t . is ( random . stringWithBytes ( 16 , [ 0x20 , 0xf1 ] ) , 'ACAAGGAT' )
70
70
} )
71
71
72
72
test ( 'Char Set Base 2 Strings' , t => {
73
73
let random = new Random ( charSet2 )
74
- t . is ( random . stringWithBytes ( 1 , Buffer . from ( [ 0x27 ] ) ) , '0' )
75
- t . is ( random . stringWithBytes ( 2 , Buffer . from ( [ 0x27 ] ) ) , '00' )
76
- t . is ( random . stringWithBytes ( 3 , Buffer . from ( [ 0x27 ] ) ) , '001' )
77
- t . is ( random . stringWithBytes ( 4 , Buffer . from ( [ 0x27 ] ) ) , '0010' )
78
- t . is ( random . stringWithBytes ( 5 , Buffer . from ( [ 0x27 ] ) ) , '00100' )
79
- t . is ( random . stringWithBytes ( 6 , Buffer . from ( [ 0x27 ] ) ) , '001001' )
80
- t . is ( random . stringWithBytes ( 7 , Buffer . from ( [ 0x27 ] ) ) , '0010011' )
81
- t . is ( random . stringWithBytes ( 8 , Buffer . from ( [ 0x27 ] ) ) , '00100111' )
82
- t . is ( random . stringWithBytes ( 9 , Buffer . from ( [ 0xe3 , 0xe9 ] ) ) , '111000111' )
83
- t . is ( random . stringWithBytes ( 16 , Buffer . from ( [ 0xe3 , 0xe9 ] ) ) , '1110001111101001' )
74
+ t . is ( random . stringWithBytes ( 1 , [ 0x27 ] ) , '0' )
75
+ t . is ( random . stringWithBytes ( 2 , [ 0x27 ] ) , '00' )
76
+ t . is ( random . stringWithBytes ( 3 , [ 0x27 ] ) , '001' )
77
+ t . is ( random . stringWithBytes ( 4 , [ 0x27 ] ) , '0010' )
78
+ t . is ( random . stringWithBytes ( 5 , [ 0x27 ] ) , '00100' )
79
+ t . is ( random . stringWithBytes ( 6 , [ 0x27 ] ) , '001001' )
80
+ t . is ( random . stringWithBytes ( 7 , [ 0x27 ] ) , '0010011' )
81
+ t . is ( random . stringWithBytes ( 8 , [ 0x27 ] ) , '00100111' )
82
+ t . is ( random . stringWithBytes ( 9 , [ 0xe3 , 0xe9 ] ) , '111000111' )
83
+ t . is ( random . stringWithBytes ( 16 , [ 0xe3 , 0xe9 ] ) , '1110001111101001' )
84
84
} )
85
85
86
86
test ( 'Char Set Strings' , t => {
@@ -108,7 +108,7 @@ test('Invalid bytes', t => {
108
108
let regex = / I n s u f f i c i e n t /
109
109
110
110
random = new Random ( charSet64 )
111
- t . regex ( invalidBytes ( random , 7 , [ 1 ] ) , regex )
111
+ t . regex ( invalidBytes ( random , 7 , [ 1 ] ) , regex )
112
112
t . regex ( invalidBytes ( random , 13 , [ 1 , 2 ] ) , regex )
113
113
t . regex ( invalidBytes ( random , 25 , [ 1 , 2 , 3 ] ) , regex )
114
114
t . regex ( invalidBytes ( random , 31 , [ 1 , 2 , 3 , 4 ] ) , regex )
@@ -118,9 +118,9 @@ test('Invalid bytes', t => {
118
118
t . regex ( invalidBytes ( random , 16 , [ 1 , 2 ] ) , regex )
119
119
t . regex ( invalidBytes ( random , 21 , [ 1 , 2 , 3 ] ) , regex )
120
120
t . regex ( invalidBytes ( random , 31 , [ 1 , 2 , 3 , 4 ] ) , regex )
121
+ t . regex ( invalidBytes ( random , 32 , [ 1 , 2 , 3 , 4 ] ) , regex )
121
122
t . regex ( invalidBytes ( random , 41 , [ 1 , 2 , 3 , 4 , 5 ] ) , regex )
122
123
t . regex ( invalidBytes ( random , 46 , [ 1 , 2 , 3 , 4 , 5 , 6 ] ) , regex )
123
- t . regex ( invalidBytes ( random , 32 , [ 250 , 200 , 150 , 100 ] ) , regex )
124
124
125
125
random = new Random ( charSet16 )
126
126
t . regex ( invalidBytes ( random , 9 , [ 1 ] ) , regex )
0 commit comments