Exemplo n.º 1
0
        public void TestFindRoot()
        {
            var func = new Func <double, double>(x => 5 * Math.Pow(x, 3) + 2 * Math.Pow(x, 2) + 4 * x + 1);

            var result = Dsp.FindRoot(func, 0, 1);
            var target = -0.261840345691399;

            Assert.AreEqual(result, target, 1e-14);

            var func2 = new Func <double, double>(x => Math.Pow(x, 2) + 2);

            Assert.Throws <Exception>(() => Dsp.FindRoot(func2, 0, 1));

            Assert.Throws <ArgumentNullException>(() => Dsp.FindRoot(null, 0, 1));
            Assert.Throws <ArgumentOutOfRangeException>(() => Dsp.FindRoot(func, 0, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => Dsp.FindRoot(func, 0, 1, -1));
        }