public void GenerateConnectionsWith_WithExistingConnectionInput_DoesNotAddNewOutgoingConnection() { // Act _hiddenNeuron.GenerateConnectionsWith(_inputNeuron); _hiddenNeuron.GenerateConnectionsWith(_inputNeuron); _hiddenNeuron.GenerateConnectionsWith(_inputNeuron); _hiddenNeuron.GenerateConnectionsWith(_inputNeuron); // Assert Assert.IsTrue(_inputNeuron.GetOutgoingConnections().Count() == 1); }
/// <summary> /// Creates the incoming and outgoing connections between this neuron and a input neuron. /// </summary> /// <param name="neuron">The input neuron to connect this neuron to.</param> public void GenerateConnectionsWith(IInputNeuron neuron) { if (neuron == null) { throw new ArgumentNullException("neuron"); } // Create connection only if this neuron doesn't already have an incoming connection from the input neuron. if (!GetIncomingConnections().Any(c => c.FromNeuron == neuron)) { Connections.Add(new IncomingConnection(neuron)); } // Create connection only if the input neuron doesn't already have an outgoing connection to this neuron. if (!neuron.GetOutgoingConnections().Any(c => c.ToNeuron == this)) { neuron.Connections.Add(new OutgoingConnection(this)); } }