Exemple #1
0
        public void LoadSettings(SavedSettings settings)
        {
            Rotor1 = ComponentFactory.CreateRotor(settings.Slot1.RotorType, RotorSlot.One, settings.Slot1.Position);
            Rotor2 = ComponentFactory.CreateRotor(settings.Slot2.RotorType, RotorSlot.Two, settings.Slot2.Position);
            Rotor3 = ComponentFactory.CreateRotor(settings.Slot3.RotorType, RotorSlot.Three, settings.Slot3.Position);

            Reflector = ComponentFactory.CreateReflector(settings.ReflectorType);
            Plugboard = ComponentFactory.CreatePlugboard(settings.PlugboardConnections);

            InitializeComponentList();
        }
Exemple #2
0
        public void Move_GetCorrectPosition(int position, int steps, int expectedPosition)
        {
            // Arrange
            var componentFactory = new ComponentFactory(new UtilityFactory());
            var rotor            = componentFactory.CreateRotor(RotorType.I, RotorSlot.One, position);

            // Act
            rotor.Move(steps);
            var resultPosition = rotor.PositionShift;

            //Assert
            Assert.Equal(resultPosition, expectedPosition);
        }
Exemple #3
0
        public async void Process_GetCorrectOutput(char inputLetter, char expectedLetter, bool step, bool expectedStep, int position, int expectedPosition,
                                                   RotorType type = RotorType.I, RotorSlot slot = RotorSlot.One)
        {
            // Arrange
            var utilityFactory   = new UtilityFactory();
            var componentFactory = new ComponentFactory(utilityFactory);
            var rotor            = componentFactory.CreateRotor(type, slot, position);
            var inputValue       = CommonHelper.LetterToNumber(inputLetter);
            var signal           = await utilityFactory.CreateSignal(inputValue, step, SignalDirection.In);

            // Act
            var resultSignal = await rotor.Process(signal);

            var resultValue  = resultSignal.Value;
            var resultLetter = CommonHelper.NumberToLetter(resultValue);
            var resultStep   = resultSignal.Step;

            // Assert
            Assert.Equal(expectedLetter, resultLetter);
            Assert.Equal(expectedStep, resultStep);
            Assert.Equal(expectedPosition, rotor.PositionShift);
        }