Пример #1
0
        void TestDerivative(Expression <Func <double, double> > function)
        {
            var    f         = function.Compile();
            double eps       = 1e-7;
            var    dfunction = Algebra.Differentiate(function);
            var    df        = dfunction.Compile();

            for (double x = 0; x < 5; x += 0.1)
            {
                Assert.AreEqual(df(x), (f(x + eps) - f(x)) / eps, 1e-5, $"Error on function {function.Body}");
            }
        }
        public void InformativeMessage_OnUnknownFunction()
        {
            var ex = Assert.Throws <ArgumentException>(() => Algebra.Differentiate(z => Math.Max(z, 2 * z)));

            Assert.That(ex.Message, Does.Contain("Max"));
        }
        public void InformativeMessage_OnNotSupportedSyntax()
        {
            var ex = Assert.Throws <ArgumentException>(() => Algebra.Differentiate(z => z.ToString().Length));

            Assert.That(ex.Message, Does.Contain("ToString"));
        }