Пример #1
0
        public void CanNegate(string expression)
        {
            var original = MathElement.Parse(expression);

            var copy = original.Negated();

            Assert.AreNotSame(original, copy);
            Assert.AreNotEqual(original.ToString(), copy.ToString());

            var reverted = copy.Negated();

            Assert.AreNotSame(original, reverted);
            Assert.AreEqual(original.ToString(), reverted.ToString());
        }
Пример #2
0
        public void NewtonMethodTests(string expression, double multiplicity, double startingPoint, double expected)
        {
            // Only testing the real part, as it makes it simpler to pass compile-time
            // inputs. The outcome should be the same for complex numbers, especially
            // given that the Complex library already existed

            var element = MathElement.Parse(expression);
            var newton  = element.ToNewtonFunction(new Complex(multiplicity, 0));
            var func    = newton.ToFunc();

            var options = new NewtonOptions
            {
                MaxIterations = 50,
                Precision     = 1e-3,
                StartingPoint = new Complex(startingPoint, 0),
            };

            var result = MathUtils.NewtonMethod(func, options);

            Assert.AreEqual(expected, result.Solution.Real, 1e-2);
        }
Пример #3
0
        public string CanFormatExpression(string expression)
        {
            var element = MathElement.Parse(expression);

            return(element.ToString());
        }
Пример #4
0
 public void CanDetectMalformedExpressions(string expression)
 {
     Assert.Throws <ParseException>(() => MathElement.Parse(expression));
 }