A Plugboard

Along the way refactored some things into a super class called Cryptor
This commit is contained in:
Eryn Wells 2015-07-18 18:37:58 -07:00
parent f997e84639
commit ed0b46b601
2 changed files with 98 additions and 12 deletions

View file

@ -9,8 +9,9 @@
import XCTest
@testable import Enigma
let alphaSeries = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
class RotorTests: XCTestCase {
let alphaSeries = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
let rotorSeries = "EKMFLGDQVZNTOWYHXUSPAIBRCJ"
func testThatUnadvancedSubstitutionWorks() {
@ -28,4 +29,20 @@ class RotorTests: XCTestCase {
XCTAssertEqual(try! rotor.encode(plainCharacter), cipherCharacter)
}
}
}
class PlugboardTests: XCTestCase {
func testThatEmptyPlugboardPassesThroughAllCharacters() {
let plugboard = try! Enigma.Plugboard()
for c in alphaSeries.characters {
XCTAssertEqual(try! plugboard.encode(c), c)
}
}
func testThatPlugboardPairsAreBidirectional() {
let plugboard = try! Enigma.Plugboard(pairs: [("A", "H")])
XCTAssertEqual(try! plugboard.encode("A"), "H")
XCTAssertEqual(try! plugboard.encode("H"), "A")
}
}