Пример #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();
        }
Пример #2
0
        public void AddConnection_NotAllowRecursiveConnection()
        {
            // Arrange
            var factory   = new ComponentFactory(new UtilityFactory());
            var plugboard = factory.CreatePlugboard();

            // Act
            plugboard.AddConnection('A', 'A');

            // Assert
            Assert.Empty(plugboard.Connections);
        }
Пример #3
0
        public void AddConnection_NotAllowSameConnections(char from, char to, Dictionary <char, char> connections)
        {
            // Arrange
            var factory          = new ComponentFactory(new UtilityFactory());
            var plugboard        = factory.CreatePlugboard(connections);
            var connectionsCount = plugboard.Connections.Count;

            // Act
            plugboard.AddConnection(from, to);

            // Assert
            Assert.True(plugboard.Connections.Count == connectionsCount);
        }
Пример #4
0
        public void AddConnection_EmptyDictionaryAndCorrectConnections(char from, char to)
        {
            // Arrange
            var factory   = new ComponentFactory(new UtilityFactory());
            var plugboard = factory.CreatePlugboard();

            // Act
            plugboard.AddConnection(from, to);
            var connections = plugboard.Connections;

            // Assert
            Assert.True(connections.ContainsKey(from));
            Assert.True(connections[from] == to);
            Assert.True(connections.ContainsKey(to));
            Assert.True(connections[to] == from);
        }
Пример #5
0
        public async void Process_GetCorrectOutput(Dictionary <char, char> connections, char inputLetter, char expectedLetter, bool step, bool expectedStep)
        {
            // Arrange
            var utilityFactory = new UtilityFactory();
            var factory        = new ComponentFactory(utilityFactory);
            var plugboard      = factory.CreatePlugboard(connections);
            var inputValue     = CommonHelper.LetterToNumber(inputLetter);
            var signal         = await utilityFactory.CreateSignal(inputValue, step, SignalDirection.In);

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

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

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