public void Train_TrainsTheNetwork()
        {
            //// SETUP

            const int NumEpochs = 3;
            const float LearningRate = 0.1f;
            const float Momentum = 0.9f;
            const double FinalError = 99.99d;

            var inputs = new[] { new[] { 1.0d, 2.0d }, new[] { 3.0d, 4.0d } };
            var ideals = new[] { new[] { 5.0d, 6.0d }, new[] { 7.0d, 8.0d } };
            var outputs = new[] { new[] { 3.5d, 5.5d }, new[] { 7.5d, 9.5d } };
            var overallErrors = new[]
                {
                    new[] { ideals[0][0] - outputs[0][0], ideals[0][1] - outputs[0][1] },
                    new[] { ideals[1][0] - outputs[1][0], ideals[1][1] - outputs[1][1] }
                };
            var finalErrors = new[] { new[] { 1.5d, 2.5d }, new[] { 3.5d, 4.5d } };

            var mockErrorCalc = new Mock<IErrorCalculator>();
            mockErrorCalc.Setup(mock => mock.Calculate()).Returns(FinalError);

            // Create 2 input nodes and 2 output nodes.
            var mockInputNode1 = new Mock<ISupervisedLearnerNode>();
            var mockInputNode2 = new Mock<ISupervisedLearnerNode>();
            var mockOutputNode1 = new Mock<ISupervisedLearnerNode>();
            var mockOutputNode2 = new Mock<ISupervisedLearnerNode>();

            // Program nodes to report input/output sizes.
            mockInputNode1.SetupGet(mock => mock.InputSize).Returns(1);
            mockInputNode2.SetupGet(mock => mock.InputSize).Returns(1);
            mockOutputNode1.SetupGet(mock => mock.OutputSize).Returns(1);
            mockOutputNode2.SetupGet(mock => mock.OutputSize).Returns(1);

            // Program output nodes to return output values based on inputs.
            mockInputNode1.Setup(mock => mock.Fire(new[] { inputs[0][0] })).Callback(() => mockOutputNode1.SetupGet(mock => mock.CachedOutputs).Returns(new[] { outputs[0][0] }));
            mockInputNode2.Setup(mock => mock.Fire(new[] { inputs[0][1] })).Callback(() => mockOutputNode2.SetupGet(mock => mock.CachedOutputs).Returns(new[] { outputs[0][1] }));
            mockInputNode1.Setup(mock => mock.Fire(new[] { inputs[1][0] })).Callback(() => mockOutputNode1.SetupGet(mock => mock.CachedOutputs).Returns(new[] { outputs[1][0] }));
            mockInputNode2.Setup(mock => mock.Fire(new[] { inputs[1][1] })).Callback(() => mockOutputNode2.SetupGet(mock => mock.CachedOutputs).Returns(new[] { outputs[1][1] }));

            // Program input nodes to return final error based on overal errors.
            mockOutputNode1.Setup(mock => mock.CalculateError(overallErrors[0][0])).Callback(
                () => mockInputNode1.SetupGet(mock => mock.CachedErrors).Returns(new[] { finalErrors[0][0] }));
            mockOutputNode1.Setup(mock => mock.CalculateError(overallErrors[1][0])).Callback(
                () => mockInputNode1.SetupGet(mock => mock.CachedErrors).Returns(new[] { finalErrors[1][0] }));
            mockOutputNode2.Setup(mock => mock.CalculateError(overallErrors[0][1])).Callback(
                () => mockInputNode2.SetupGet(mock => mock.CachedErrors).Returns(new[] { finalErrors[0][1] }));
            mockOutputNode2.Setup(mock => mock.CalculateError(overallErrors[1][1])).Callback(
                () => mockInputNode2.SetupGet(mock => mock.CachedErrors).Returns(new[] { finalErrors[1][1] }));

            // Create the network
            var network = new BackpropagationNetwork(mockErrorCalc.Object);
            network.AddInputNode(mockInputNode1.Object);
            network.AddInputNode(mockInputNode2.Object);
            network.AddOutputNode(mockOutputNode1.Object);
            network.AddOutputNode(mockOutputNode2.Object);

            // Execute
            var actualError = network.Train(NumEpochs, LearningRate, Momentum, inputs, ideals);

            //// Verify

            // Use of error calculator
            mockErrorCalc.Verify(mock => mock.Reset(), Times.Exactly(NumEpochs));
            mockErrorCalc.Verify(mock => mock.AddToErrorCalc(overallErrors[0]), Times.Exactly(NumEpochs));
            mockErrorCalc.Verify(mock => mock.AddToErrorCalc(overallErrors[1]), Times.Exactly(NumEpochs));
            mockErrorCalc.Verify(mock => mock.Calculate(), Times.Once());

            // Use of input nodes
            mockInputNode1.Verify(mock => mock.Fire(new[] { inputs[0][0] }), Times.Exactly(NumEpochs));
            mockInputNode1.Verify(mock => mock.Fire(new[] { inputs[1][0] }), Times.Exactly(NumEpochs));
            mockInputNode2.Verify(mock => mock.Fire(new[] { inputs[0][1] }), Times.Exactly(NumEpochs));
            mockInputNode2.Verify(mock => mock.Fire(new[] { inputs[1][1] }), Times.Exactly(NumEpochs));

            mockInputNode1.Verify(mock => mock.ClearCachedErrors(), Times.Exactly(NumEpochs * inputs.Length));
            mockInputNode2.Verify(mock => mock.ClearCachedErrors(), Times.Exactly(NumEpochs * inputs.Length));

            mockInputNode1.Verify(mock => mock.ApplyWeightAdjustments(LearningRate, Momentum), Times.Exactly(NumEpochs));
            mockInputNode2.Verify(mock => mock.ApplyWeightAdjustments(LearningRate, Momentum), Times.Exactly(NumEpochs));

            // Use of output nodes
            mockOutputNode1.VerifyGet(mock => mock.CachedOutputs, Times.AtLeast(NumEpochs));
            mockOutputNode2.VerifyGet(mock => mock.CachedOutputs, Times.AtLeast(NumEpochs));

            mockOutputNode1.Verify(mock => mock.CalculateError(overallErrors[0][0]), Times.Exactly(NumEpochs));
            mockOutputNode1.Verify(mock => mock.CalculateError(overallErrors[1][0]), Times.Exactly(NumEpochs));
            mockOutputNode2.Verify(mock => mock.CalculateError(overallErrors[0][1]), Times.Exactly(NumEpochs));
            mockOutputNode2.Verify(mock => mock.CalculateError(overallErrors[1][1]), Times.Exactly(NumEpochs));

            // Verify Error
            Assert.AreEqual(FinalError, actualError);
        }