File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,15 @@ public class Random {
5050 return charSet. chars
5151 }
5252
53+ public func use( _ charSet: CharSet ) {
54+ self . charSet = charSet
55+ }
56+
57+ public func use( _ chars: String ) throws {
58+ let charSet = try CharSet ( chars)
59+ self . charSet = charSet
60+ }
61+
5362 // MARK: - Public API
5463 //
5564 /// Generates a random string.
Original file line number Diff line number Diff line change @@ -218,7 +218,20 @@ class RandomTests: XCTestCase {
218218 XCTFail ( " Error not a EntropyStringError " )
219219 }
220220 }
221+ }
222+
223+ func testUseCharSet( ) {
224+ random = Random ( . charSet32)
225+ XCTAssertEqual ( random. chars, CharSet . charSet32. chars)
226+ random. use ( . charSet16)
227+ XCTAssertEqual ( random. chars, CharSet . charSet16. chars)
228+ }
221229
230+ func testUseChars( ) {
231+ random = try ! Random ( " abce " )
232+ XCTAssertEqual ( random. chars, " abce " )
233+ try ! random. use ( " ECBA " )
234+ XCTAssertEqual ( random. chars, " ECBA " )
222235 }
223236
224237 #if !os(Linux)
You can’t perform that action at this time.
0 commit comments