Example #1
0
        public static void FindNthRoot_NumberDegreePrecisionResult(double number, int degree,
                                                                   double precision, double expected)
        {
            double actual = RootAlgorithm.FindNthRoot(number, degree, precision);

            Assert.AreEqual(expected, actual, precision);
        }
        public void FindNthRoot_NumberResultWithNegativeDegree()
        {
            double number   = 97.65625;
            int    degree   = -5;
            double expected = 0.4;

            var actual = RootAlgorithm.FindNthRoot(number, degree);

            Assert.AreEqual(expected, actual, 0.0001);
        }
        public void FindNthRoot_NumberResultWithDouble()
        {
            double number   = 0.001;
            int    degree   = 3;
            double expected = 0.1;

            var actual = RootAlgorithm.FindNthRoot(number, degree);

            Assert.AreEqual(expected, actual, 0.0001);
        }
        public void FindNthRoot_NumberResultWithPositiveDegree()
        {
            double number   = 1;
            int    degree   = 5;
            int    expected = 1;

            var actual = RootAlgorithm.FindNthRoot(number, degree);

            Assert.AreEqual(expected, actual, 0.0001);
        }
Example #5
0
 public void FindNthRoot_ArgumentOutOfRangeException(double number, int degree,
                                                     double precision, double expected)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => RootAlgorithm.FindNthRoot(number, degree, precision));
 }
Example #6
0
        public static void FindNthRoot_NumberDegreeResult(double number, int degree, double expected)
        {
            double actual = RootAlgorithm.FindNthRoot(number, degree);

            Assert.AreEqual(expected, actual, 0.0001);
        }
 public void FilterDigit_ThrowArgumentOutOfRangeException()
 => RootAlgorithm.FindNthRoot(999.9, 3, -7);
Example #8
0
        public static IterationResults Find(obj_function funct, double x_lower, double x_upper, RootAlgorithm algorithm)
        {
            RootBase root;

            switch (algorithm)
            {
            case RootAlgorithm.Bisection:
                root = new Bisection();
                break;

            case RootAlgorithm.Brent:
                root = new Brent();
                break;

            case RootAlgorithm.FalsePosition:
                root = new FalsePosition();
                break;

            case RootAlgorithm.Secant:
                root = new Secant();
                break;

            case RootAlgorithm.Ridders:
                root = new Ridders();
                break;

            case RootAlgorithm.Steffenson:
                root = new Steffenson();
                break;

            default:
                root = new Brent();
                break;
            }
            return(root.Solve(funct, x_lower, x_upper));
        }