Пример #1
0
        public void FunctionTest()
        {
            Quadratic target = new Quadratic(0);

            double[] x = new double[] { 1, 1 };
            double[] y = new double[] { 1, 1 };

            double expected = System.Math.Pow(x.InnerProduct(y), 2);
            double actual   = target.Function(x, y);

            Assert.AreEqual(expected, actual);


            x = new double[] { 0.5, 2.0 };
            y = new double[] { 1.3, -0.2 };

            expected = 0.0625;
            actual   = target.Function(x, y);

            Assert.AreEqual(expected, actual);


            target = new Quadratic(4.2);

            x = new double[] { 9.4, 22.1 };
            y = new double[] { -6.21, 4 };

            expected = System.Math.Pow(x.InnerProduct(y) + 4.2, 2);
            actual   = target.Function(x, y);
            Assert.AreEqual(expected, actual, 0.0001);
        }