Commit 983db3132e
Verified · cmc
Layout: unified · split
Tests/KeycaskCoreTests/GeneratorTests.swift +8 −5
| @@ -35,12 +35,15 @@ import Testing | ||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | @Test func passphraseUsesWordsFromTheList() { |
| 38 | let words = Set(Wordlist.words) | |
| 39 | let p = Generator.passphrase(words: 5) | |
| 40 | let parts = p.split(separator: "-").map(String.init) | |
| 41 | #expect(parts.count == 5) | |
| 42 | #expect(parts.allSatisfy { words.contains($0) }) | |
| 38 | var a = Counter() | |
| 39 | var b = Counter() | |
| 40 | let produced = Generator.passphrase(words: 5, using: &a) | |
| 41 | let count = UInt32(Wordlist.words.count) | |
| 42 | let expected = (0..<5).map { _ in Wordlist.words[Int(b.next(upperBound: count))] } | |
| 43 | .joined(separator: Generator.wordSeparator) | |
| 44 | #expect(produced == expected) | |
| 43 | 45 | #expect(Generator.passphrase(words: 0) == "") |
| 46 | #expect(!Generator.passphrase(words: 3).isEmpty) | |
| 44 | 47 | } |
| 45 | 48 | |
| 46 | 49 | @Test func seededOutputIsReproducible() { |