Exemplo n.º 1
0
        public void E_Sim_Instead_Sin_Test()
        {
            FunctionInformation_V2 FI = new FunctionInformation_V2("2 * sim (x) + 3 * cos(y) - sin (z) / cos(z)");
            var dict = new Dictionary <string, double>(new List <KeyValuePair <string, double> > {
                new KeyValuePair <string, double>("x", pi / 2),
                new KeyValuePair <string, double>("y", pi),
                new KeyValuePair <string, double>("z", pi / 4)
            });

            var firstValue = FI.GetValue(dict);

            FI.FixValue("x", pi / 2);
            FI.FixValue("y", pi);
            FI.FixValue("z", pi / 4);

            var secondValue = FI.GetValue();

            Assert.AreEqual(3, FI.GetTermCount());
            Assert.AreEqual(new List <string>()
            {
                "x", "y", "z"
            }, FI.GetVariables());
            Assert.AreEqual(-2.0, firstValue, delta);
            Assert.AreEqual(firstValue, secondValue, delta, "Несовпадение значений при вычислении функции двумя способами");
        }
Exemplo n.º 2
0
        public void B_DifferentTestCase_Test_6()
        {
            FunctionInformation_V2 FI = new FunctionInformation_V2("cos(z + w) ^ 2 - x * p + y");
            var dict = new Dictionary <string, double>(new List <KeyValuePair <string, double> > {
                new KeyValuePair <string, double>("x", 4),
                new KeyValuePair <string, double>("y", 11),
                new KeyValuePair <string, double>("z", pi / 2),
                new KeyValuePair <string, double>("w", pi / 2),
                new KeyValuePair <string, double>("p", 3)
            });

            var firstValue = FI.GetValue(dict);

            FI.FixValue("x", 4);
            FI.FixValue("y", 11);
            FI.FixValue("z", pi / 2);
            FI.FixValue("w", pi / 2);
            FI.FixValue("p", 3);

            var secondValue = FI.GetValue();

            Assert.AreEqual(3, FI.GetTermCount());
            Assert.AreEqual(new List <string>()
            {
                "z", "w", "x", "p", "y"
            }, FI.GetVariables());
            Assert.AreEqual(0.0, firstValue, delta);
            Assert.AreEqual(firstValue, secondValue, delta, "Несовпадение значений при вычислении функции двумя способами");
        }
Exemplo n.º 3
0
        public void B_DifferentTestCase_Test_5()
        {
            FunctionInformation_V2 FI = new FunctionInformation_V2("y + sin(x * z) * 2");
            var dict = new Dictionary <string, double>(new List <KeyValuePair <string, double> > {
                new KeyValuePair <string, double>("x", pi),
                new KeyValuePair <string, double>("y", 3),
                new KeyValuePair <string, double>("z", 0.5)
            });

            var firstValue = FI.GetValue(dict);

            FI.FixValue("x", pi);
            FI.FixValue("y", 3);
            FI.FixValue("z", 0.5);

            var secondValue = FI.GetValue();

            Assert.AreEqual(2, FI.GetTermCount());
            Assert.AreEqual(new List <string>()
            {
                "y", "x", "z"
            }, FI.GetVariables());
            Assert.AreEqual(5.0, firstValue, delta);
            Assert.AreEqual(firstValue, secondValue, delta, "Несовпадение значений при вычислении функции двумя способами");
        }
Exemplo n.º 4
0
        public void A_Base_Equals_DictValue_And_FixValue_Test()
        {
            FunctionInformation_V2 FI = new FunctionInformation_V2("x * z + y / p");
            var dict = new Dictionary <string, double>(new List <KeyValuePair <string, double> > {
                new KeyValuePair <string, double>("x", 6),
                new KeyValuePair <string, double>("y", 2),
                new KeyValuePair <string, double>("z", 8),
                new KeyValuePair <string, double>("p", 6),
            });

            var firstValue = FI.GetValue(dict);

            FI.FixValue("x", 6);
            FI.FixValue("y", 2);
            FI.FixValue("z", 8);
            FI.FixValue("p", 6);

            var secondValue = FI.GetValue();

            Assert.AreEqual(2, FI.GetTermCount());
            Assert.AreEqual(new List <string>()
            {
                "x", "z", "y", "p"
            }, FI.GetVariables());
            Assert.AreEqual(48.3333333333, firstValue, delta);
            Assert.AreEqual(firstValue, secondValue, delta);
        }
Exemplo n.º 5
0
        public void A_Base_FixValueAndGetValue_Test()
        {
            FunctionInformation_V2 FI = new FunctionInformation_V2("x");

            FI.FixValue("x", 2.0);

            Assert.AreEqual(1, FI.GetTermCount());
            Assert.AreEqual(new List <string>()
            {
                "x"
            }, FI.GetVariables());
            Assert.AreEqual(2.0, FI.GetValue(), delta);
        }
Exemplo n.º 6
0
        public void B_DifferentTestCase_Test_7()
        {
            FunctionInformation_V2 FI = new FunctionInformation_V2("2 ^( x ^ (y^2) ) - 2 ^ ( y ^ (x^2))");
            var dict = new Dictionary <string, double>(new List <KeyValuePair <string, double> > {
                new KeyValuePair <string, double>("x", 2),
                new KeyValuePair <string, double>("y", 1)
            });

            var firstValue = FI.GetValue(dict);

            FI.FixValue("x", 2);
            FI.FixValue("y", 1);

            var secondValue = FI.GetValue();

            Assert.AreEqual(2, FI.GetTermCount());
            Assert.AreEqual(new List <string>()
            {
                "x", "y"
            }, FI.GetVariables());
            Assert.AreEqual(2.0, firstValue, delta);
            Assert.AreEqual(firstValue, secondValue, delta, "Несовпадение значений при вычислении функции двумя способами");
        }