Exemplo n.º 1
0
        private void TestRotorReflection(string rotorType, char offset)
        {
            var rotor = Rotor.Create(rotorType, offset);
            IEnumerable <char> mappedLetters   = AlphabetLetters.Select(l => rotor.GetMappedLetter(l)).ToArray();
            IEnumerable <char> reversedLetters = mappedLetters.Select(l => rotor.GetMappedLetter(l, LetterMapper.MappingDirection.LeftToRight));

            Assert.IsTrue(SequencesOrderedEqual(AlphabetLetters, reversedLetters));
        }
Exemplo n.º 2
0
 public void TestRotorNotches()
 {
     foreach (var kvp in ExpectedNotches)
     {
         var rotor = Rotor.Create(kvp.Key);
         IEnumerable <bool> notches = BuildNotchesPredicateFromLetters(kvp.Value);
         Assert.IsTrue(AlphabetLetters.Zip(notches, (letter, isNotch) => rotor.IsNotch(letter) == isNotch).All(res => res));
     }
 }
Exemplo n.º 3
0
 public void TestDefaultRotorMappings()
 {
     foreach (var kvp in ExpectedMappings)
     {
         var rotor = Rotor.Create(kvp.Key);
         IEnumerable <char> mappedLetters = AlphabetLetters.Select(letter => rotor.GetMappedLetter(letter));
         Assert.IsTrue(SequencesOrderedEqual(kvp.Value, mappedLetters));
     }
 }
Exemplo n.º 4
0
        public void TestNotch()
        {
            var socket = new RotorSocket(Rotor.Create("I"));

            while (!socket.IsSocketInNotchPosition)
            {
                socket.Advance();
            }
            Assert.AreEqual('Q', socket.CurrentRingLetter);
        }
Exemplo n.º 5
0
        public void TestLetterMappingsWithRotorOffsetSettings()
        {
            var socket = new RotorSocket(Rotor.Create("I", 'B'));

            Assert.AreEqual('K', socket.GetMappedLetter('A'));
            Assert.AreEqual('A', socket.GetMappedLetter('K', LetterMapper.MappingDirection.LeftToRight));
            socket.Advance();
            Assert.AreEqual('E', socket.GetMappedLetter('A'));
            Assert.AreEqual('A', socket.GetMappedLetter('E', LetterMapper.MappingDirection.LeftToRight));
        }
Exemplo n.º 6
0
        public void TestLetterMappings()
        {
            var socket = new RotorSocket(Rotor.Create("I"));

            Assert.AreEqual('E', socket.GetMappedLetter('A'));
            Assert.AreEqual('A', socket.GetMappedLetter('E', LetterMapper.MappingDirection.LeftToRight));

            //If for example rotor I is in the B-position, an A enters at the letter B
            //which is wired to the K. Because of the offset this K enters the next rotor in the J position.
            socket.Advance();
            Assert.AreEqual('J', socket.GetMappedLetter('A'));
            Assert.AreEqual('A', socket.GetMappedLetter('J', LetterMapper.MappingDirection.LeftToRight));
        }
Exemplo n.º 7
0
        public void TestRotorRingSetting()
        {
            //LoopAllRotorsAndOffsets(TestRotorOffset);
            var rotorWithOffset = Rotor.Create("I");

            Assert.AreEqual('E', rotorWithOffset.GetMappedLetter('A'));
            Assert.AreEqual('A', rotorWithOffset.GetMappedLetter('E', LetterMapper.MappingDirection.LeftToRight));
            rotorWithOffset = Rotor.Create("I", 'B');
            Assert.AreEqual('K', rotorWithOffset.GetMappedLetter('A'));
            Assert.AreEqual('A', rotorWithOffset.GetMappedLetter('K', LetterMapper.MappingDirection.LeftToRight));
            Assert.AreEqual('F', rotorWithOffset.GetMappedLetter('B'));
            Assert.AreEqual('B', rotorWithOffset.GetMappedLetter('F', LetterMapper.MappingDirection.LeftToRight));
        }
Exemplo n.º 8
0
        private void TestRotorOffset(string rotorType, char offset)
        {
            var rotorWithOffset = Rotor.Create(rotorType, offset);

            IEnumerable <char> newMapping    = RotateLeft(ExpectedMappings[rotorType], offset - 'A');
            IEnumerable <char> mappedLetters = AlphabetLetters.Select(letter => rotorWithOffset.GetMappedLetter(letter)).ToArray();

            Assert.IsTrue(SequencesOrderedEqual(newMapping, mappedLetters));

            var reverseSequence = mappedLetters.Select(letter => rotorWithOffset.GetMappedLetter(letter, LetterMapper.MappingDirection.LeftToRight));

            Assert.IsTrue(SequencesOrderedEqual(reverseSequence, AlphabetLetters));
        }
Exemplo n.º 9
0
        public void TestRotorOffsets()
        {
            var socket = new RotorSocket(Rotor.Create("I"));

            Assert.AreEqual('A', socket.CurrentRingLetter);
            socket.Advance();
            Assert.AreEqual('B', socket.CurrentRingLetter);
            socket.Reset();
            Assert.AreEqual('A', socket.CurrentRingLetter);
            for (int i = 0; i < 26; i++)
            {
                socket.Advance();
            }
            Assert.AreEqual('A', socket.CurrentRingLetter);
        }
Exemplo n.º 10
0
 public void SetupRotor(RotorInfo rotorInfo)
 {
     SetupRotor(Rotor.Create(rotorInfo.Type, rotorInfo.RingSettingOffset), rotorInfo.StartingOffset);
 }