From f997e84639ba2e0b0430f984d73852c46cc75d50 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 18 Jul 2015 10:47:14 -0700 Subject: [PATCH] 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. --- EnigmaTests/EnigmaTests.swift | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/EnigmaTests/EnigmaTests.swift b/EnigmaTests/EnigmaTests.swift index 44145c3..b34248d 100644 --- a/EnigmaTests/EnigmaTests.swift +++ b/EnigmaTests/EnigmaTests.swift @@ -10,19 +10,21 @@ import XCTest @testable import Enigma class RotorTests: XCTestCase { + let alphaSeries = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" let rotorSeries = "EKMFLGDQVZNTOWYHXUSPAIBRCJ" - var rotor: Enigma.Rotor! - - override func setUp() { - rotor = try! Enigma.Rotor(series: rotorSeries) - } - - override func tearDown() { - rotor = nil - } func testThatUnadvancedSubstitutionWorks() { - for (plainCharacter, cipherCharacter) in zip("ABCDEFGHIJKLMNOPQRSTUVWXYZ".characters, rotorSeries.characters) { + 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) } }