enigma-machine/EnigmaTests/EnigmaTests.swift
Eryn Wells f997e84639 Add rot13 test for Rotor
This test checks the modulo functionality.

This change also refactors how tests are set up. Each test is responsible for creating its own rotor.
2015-07-18 10:47:14 -07:00

31 lines
No EOL
1,000 B
Swift

//
// EnigmaTests.swift
// EnigmaTests
//
// Created by Eryn Wells on 2015-07-18.
// Copyright © 2015 Eryn Wells. All rights reserved.
//
import XCTest
@testable import Enigma
class RotorTests: XCTestCase {
let alphaSeries = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
let rotorSeries = "EKMFLGDQVZNTOWYHXUSPAIBRCJ"
func testThatUnadvancedSubstitutionWorks() {
let rotor = try! Enigma.Rotor(series: rotorSeries)
for (plainCharacter, cipherCharacter) in zip(alphaSeries.characters, rotorSeries.characters) {
XCTAssertEqual(try! rotor.encode(plainCharacter), cipherCharacter)
}
}
func testThatRotorCanDoRot13() {
let rot13Series = "NOPQRSTUVWXYZABCDEFGHIJKLM"
let rotor = try! Enigma.Rotor(series: alphaSeries)
rotor.advance(13)
for (plainCharacter, cipherCharacter) in zip(alphaSeries.characters, rot13Series.characters) {
XCTAssertEqual(try! rotor.encode(plainCharacter), cipherCharacter)
}
}
}