Example #1
0
        public void GenerateConnectionsWith_WithExistingConnectionOutput_DoesNotAddNewIncomingConnection()
        {
            // Act
            _inputNeuron.GenerateConnectionsWith(_outputNeuron);
            _inputNeuron.GenerateConnectionsWith(_outputNeuron);
            _inputNeuron.GenerateConnectionsWith(_outputNeuron);
            _inputNeuron.GenerateConnectionsWith(_outputNeuron);

            // Assert
            Assert.IsTrue(_outputNeuron.GetIncomingConnections().Count() == 1);
        }
        /// <summary>
        /// Creates the incoming and outgoing connections between this neuron and a output neuron.
        /// </summary>
        /// <param name="neuron">The output neuron to connect this neuron to.</param>
        public void GenerateConnectionsWith(IOutputNeuron neuron)
        {
            if (neuron == null)
            {
                throw new ArgumentNullException("neuron");
            }

            // Create connection only if this neuron doesn't already have an outgoing connection to the output neuron.
            if (!GetOutgoingConnections().Any(c => c.ToNeuron == neuron))
            {
                Connections.Add(new OutgoingConnection(neuron));
            }

            // Create connection only if the output neuron doesn't already have an incoming connection from this neuron.
            if (!neuron.GetIncomingConnections().Any(c => c.FromNeuron == this))
            {
                neuron.Connections.Add(new IncomingConnection(this));
            }
        }