Ejemplo n.º 1
0
        public void ComplieTests(string equStr, double exp, params double[] nums)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation(equStr);

            double result = eq.Evaluate(nums);

            Assert.That(eq.EquationArguments.Count(), Is.EqualTo(nums.Count()));
            Assert.That(result, Is.EqualTo(exp).Within(0.1).Percent);
        }
Ejemplo n.º 2
0
        public void VarNameTests(string equStr, double exp, params double[] nums)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation(equStr);

            double result = eq.Evaluate(nums);

            Assert.That(eq.EquationArguments.Count(), Is.EqualTo(nums.Count()));
            Assert.That(eq.EquationArguments.ElementAt(0), Is.EqualTo("My.Good"));
            Assert.That(eq.EquationArguments.ElementAt(1), Is.EqualTo("Inputs.Are.Fun"));
            Assert.That(result, Is.EqualTo(exp).Within(0.1).Percent);
        }
Ejemplo n.º 3
0
        public void BinaryShouldWorkUnlessDivdeByZero(double x, double y)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation($"{x}{optStr}{y}");

            if (y == 0 && optStr == "/")
            {
                Assert.Throws <DivideByZeroException>(() => eq.Evaluate(x, y));
            }
            else
            {
                Assert.That(eq.Evaluate(x, y), Is.EqualTo(func(x, y)).Within(0.1).Percent);
            }
        }
Ejemplo n.º 4
0
        public void Variable(string equStr, double exp, params double[] nums)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation(equStr);

            double result = eq.Evaluate(nums);

            Assert.That(eq.EquationArguments.Count(), Is.EqualTo(nums.Length));
            for (int i = 0; i < nums.Length; i++)
            {
                Assert.That(eq.EquationArguments.ElementAt(i), Is.EqualTo(i.ToString()));
            }
            Assert.That(result, Is.EqualTo(exp).Within(0.1).Percent);
        }
Ejemplo n.º 5
0
        public void FunctionWithinFunctionShouldWork(double x)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation($"Pow(Pow({x},{x}),{x})");

            Assert.AreEqual(Math.Pow(Math.Pow(x, x), x), eq.Evaluate(), 1e-3);
        }
Ejemplo n.º 6
0
        public void PiShouldWork(double x)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation($"PI / 4 * {x} * {x}");

            Assert.AreEqual(Math.PI / 4 * x * x, eq.Evaluate(), 1e-3);
        }
Ejemplo n.º 7
0
        public void PowShouldWork(double x, double y)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation($"Pow({x},{y})");

            Assert.AreEqual(Math.Pow(x, y), eq.Evaluate(), 1e-3);
        }
Ejemplo n.º 8
0
        public void SqrtShouldWork(double x)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation($"Sqrt({x})");

            Assert.AreEqual(Math.Sqrt(x), eq.Evaluate(), 1e-3);
        }
Ejemplo n.º 9
0
        public void BinaryShouldWorkWithWhiteSpace(string strEq, double x, double y)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation(string.Format(strEq, x, optStr, y));

            Assert.AreEqual(func(x, y), eq.Evaluate(x, y), 0.001);
        }
Ejemplo n.º 10
0
        public void OrderOfOperations(string strEq, double exp)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation(strEq);

            Assert.That(eq.Evaluate(), Is.EqualTo(exp).Within(0.001));
        }
Ejemplo n.º 11
0
        public void UniaryMinusShouldWork(string stringEquation, double expected)
        {
            IStringEquation eq = StringEquationSetup.BuildStringEquation(stringEquation);

            Assert.AreEqual(eq.Evaluate(), expected);
        }