Skip to content

Commit d6a991d

Browse files
committed
Session ID tests
1 parent 93bcccd commit d6a991d

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Tests/EntropyStringTests/RandomTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ class RandomTests: XCTestCase {
1313
var random: Random!
1414
var charSets = [.charSet64, .charSet32, .charSet16, .charSet8, .charSet4, .charSet2] as [CharSet]
1515

16+
func testInit() {
17+
let random = Random()
18+
XCTAssertEqual(random.chars, CharSet.charSet32.chars)
19+
}
20+
21+
func testSessionID() {
22+
for charSet in charSets {
23+
let sessionIDBits = Float(128)
24+
let random = Random(charSet: charSet)
25+
let id = random.sessionID()
26+
let count = Int(ceilf(sessionIDBits / Float(charSet.bitsPerChar)))
27+
XCTAssertEqual(id.characters.count, count)
28+
}
29+
}
30+
1631
func testCharSet64() {
1732
random = Random(charSet: .charSet64)
1833
entropyString( 6, [0xdd], "3")
@@ -294,6 +309,8 @@ extension RandomTests {
294309
// Adopt XCTestCaseProvider to run test on Linux
295310
static var tests: [(String, (RandomTests) -> () throws -> ())] {
296311
return [
312+
("testInit", testInit),
313+
("testSessionID", testSessionID),
297314
("testCharSet64", testCharSet64),
298315
("testCharSet32", testCharSet32),
299316
("testCharSet16", testCharSet16),

0 commit comments

Comments
 (0)