@@ -21,15 +21,15 @@ class RandomTests: XCTestCase {
21
21
func testSessionID( ) {
22
22
for charSet in charSets {
23
23
let sessionIDBits = Float ( 128 )
24
- let random = Random ( charSet: charSet )
24
+ let random = Random ( charSet)
25
25
let id = random. sessionID ( )
26
26
let count = Int ( ceilf ( sessionIDBits / Float( charSet. bitsPerChar) ) )
27
27
XCTAssertEqual ( id. characters. count, count)
28
28
}
29
29
}
30
30
31
31
func testCharSet64( ) {
32
- random = Random ( charSet : . charSet64)
32
+ random = Random ( . charSet64)
33
33
entropyString ( 6 , [ 0xdd ] , " 3 " )
34
34
entropyString ( 12 , [ 0x78 , 0xfc ] , " eP " )
35
35
entropyString ( 18 , [ 0xc5 , 0x6f , 0x21 ] , " xW8 " )
@@ -45,7 +45,7 @@ class RandomTests: XCTestCase {
45
45
}
46
46
47
47
func testCharSet32( ) {
48
- random = Random ( charSet : . charSet32)
48
+ random = Random ( . charSet32)
49
49
entropyString ( 5 , [ 0xdd ] , " N " )
50
50
entropyString ( 10 , [ 0x78 , 0xfc ] , " p6 " )
51
51
entropyString ( 15 , [ 0x78 , 0xfc ] , " p6R " )
@@ -60,7 +60,7 @@ class RandomTests: XCTestCase {
60
60
}
61
61
62
62
func testCharSet16( ) {
63
- random = Random ( charSet : . charSet16)
63
+ random = Random ( . charSet16)
64
64
entropyString ( 4 , [ 0x9d ] , " 9 " )
65
65
entropyString ( 8 , [ 0xae ] , " ae " )
66
66
entropyString ( 12 , [ 0x01 , 0xf2 ] , " 01f " )
@@ -69,7 +69,7 @@ class RandomTests: XCTestCase {
69
69
}
70
70
71
71
func testCharSet8( ) {
72
- random = Random ( charSet : . charSet8)
72
+ random = Random ( . charSet8)
73
73
entropyString ( 3 , [ 0x5a ] , " 2 " )
74
74
entropyString ( 6 , [ 0x5a ] , " 26 " )
75
75
entropyString ( 9 , [ 0x21 , 0xa4 ] , " 103 " )
@@ -83,7 +83,7 @@ class RandomTests: XCTestCase {
83
83
}
84
84
85
85
func testCharSet4( ) {
86
- random = Random ( charSet : . charSet4)
86
+ random = Random ( . charSet4)
87
87
entropyString ( 2 , [ 0x5a ] , " T " )
88
88
entropyString ( 4 , [ 0x5a ] , " TT " )
89
89
entropyString ( 6 , [ 0x93 ] , " CTA " )
@@ -95,7 +95,7 @@ class RandomTests: XCTestCase {
95
95
}
96
96
97
97
func testCharSet2( ) {
98
- random = Random ( charSet : . charSet2)
98
+ random = Random ( . charSet2)
99
99
entropyString ( 1 , [ 0x27 ] , " 0 " )
100
100
entropyString ( 2 , [ 0x27 ] , " 00 " )
101
101
entropyString ( 3 , [ 0x27 ] , " 001 " )
@@ -110,7 +110,7 @@ class RandomTests: XCTestCase {
110
110
111
111
func testStringLengths( ) {
112
112
for charSet in charSets {
113
- let random = Random ( charSet: charSet )
113
+ let random = Random ( charSet)
114
114
let iters = 128
115
115
for i in 0 ..< iters {
116
116
let string = random. string ( bits: Float ( i) )
@@ -125,27 +125,27 @@ class RandomTests: XCTestCase {
125
125
var random : Random
126
126
var string : String
127
127
do {
128
- random = try Random ( chars : " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ9876543210_- " )
128
+ random = try Random ( " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ9876543210_- " )
129
129
string = try random. string ( bits: 72 , using: [ 0x9d , 0x99 , 0x4e , 0xa5 , 0xd2 , 0x3f , 0x8c , 0x86 , 0x80 ] )
130
130
XCTAssertEqual ( string, " NzLoPDi-JiAa " )
131
131
132
- random = try Random ( chars : " 2346789BDFGHJMNPQRTbdfghjlmnpqrt " )
132
+ random = try Random ( " 2346789BDFGHJMNPQRTbdfghjlmnpqrt " )
133
133
string = try random. string ( bits: 55 , using: [ 0xd2 , 0xe3 , 0xe9 , 0xda , 0x19 , 0x97 , 0x52 ] )
134
134
XCTAssertEqual ( string, " mHRrbgQlTqF " )
135
135
136
- random = try Random ( chars : " 0123456789ABCDEF " )
136
+ random = try Random ( " 0123456789ABCDEF " )
137
137
string = try random. string ( bits: 20 , using: [ 0xc7 , 0xc9 , 0x00 ] )
138
138
XCTAssertEqual ( string, " C7C90 " )
139
139
140
- random = try Random ( chars : " abcdefgh " )
140
+ random = try Random ( " abcdefgh " )
141
141
string = try random. string ( bits: 30 , using: [ 0xc7 , 0xc9 , 0x07 , 0xc9 ] )
142
142
XCTAssertEqual ( string, " gbheeeahgc " )
143
143
144
- random = try Random ( chars : " atcg " )
144
+ random = try Random ( " atcg " )
145
145
string = try random. string ( bits: 16 , using: [ 0x20 , 0xf1 ] )
146
146
XCTAssertEqual ( string, " acaaggat " )
147
147
148
- random = try Random ( chars : " HT " )
148
+ random = try Random ( " HT " )
149
149
string = try random. string ( bits: 16 , using: [ 0xe3 , 0xe9 ] )
150
150
XCTAssertEqual ( string, " TTTHHHTTTTTHTHHT " )
151
151
}
@@ -207,7 +207,7 @@ class RandomTests: XCTestCase {
207
207
208
208
func testNegativeEntropy( ) {
209
209
do {
210
- let random = Random ( charSet : . charSet32)
210
+ let random = Random ( . charSet32)
211
211
let _ = try random. string ( bits: - 6 , using: [ 0x33 ] )
212
212
}
213
213
catch {
@@ -224,7 +224,7 @@ class RandomTests: XCTestCase {
224
224
#if !os(Linux)
225
225
func testSecRand( ) {
226
226
for charSet in charSets {
227
- let random = Random ( charSet: charSet )
227
+ let random = Random ( charSet)
228
228
var secRand = false
229
229
_ = random. string ( bits: 36 , secRand: & secRand)
230
230
XCTAssertFalse ( secRand)
@@ -248,7 +248,7 @@ class RandomTests: XCTestCase {
248
248
249
249
func entropyString( _ bits: Float , _ charSet: CharSet , _ bytes: [ UInt8 ] , _ expected: String ) {
250
250
do {
251
- let random = Random ( charSet: charSet )
251
+ let random = Random ( charSet)
252
252
let string = try random. string ( bits: bits, using: bytes)
253
253
XCTAssertEqual ( string, expected)
254
254
}
@@ -259,7 +259,7 @@ class RandomTests: XCTestCase {
259
259
260
260
func nonUniqueChars( _ chars: String ) {
261
261
do {
262
- let _ = try Random ( chars: chars )
262
+ let _ = try Random ( chars)
263
263
XCTFail ( " Should have thrown " )
264
264
}
265
265
catch {
@@ -274,7 +274,7 @@ class RandomTests: XCTestCase {
274
274
275
275
func invalidCharCount( _ chars: String ) {
276
276
do {
277
- let _ = try Random ( chars: chars )
277
+ let _ = try Random ( chars)
278
278
XCTFail ( " Should have thrown " )
279
279
}
280
280
catch {
@@ -289,7 +289,7 @@ class RandomTests: XCTestCase {
289
289
290
290
func invalidBytes( _ bits: Float , _ charSet: CharSet , _ bytes: [ UInt8 ] ) {
291
291
do {
292
- let random = Random ( charSet: charSet )
292
+ let random = Random ( charSet)
293
293
_ = try random. string ( bits: bits, using: bytes)
294
294
XCTFail ( " Should have thrown " )
295
295
}
0 commit comments