Beispiel #1
0
        public void GreaterThan()
        {
            RPN test = new RPN("5 > 2").Compute();

            PostFix math = new PostFix(test);

            Assert.AreEqual(1, math.Compute());

            test.SetEquation("5 > 10").Compute();

            math = new PostFix(test);
            Assert.AreEqual(0, math.Compute());

            test.SetEquation("5 >= 5").Compute();

            math = new PostFix(test);
            Assert.AreEqual(1, math.Compute());

            test.SetEquation("15 >= 5").Compute();

            math = new PostFix(test);
            Assert.AreEqual(1, math.Compute());

            test.SetEquation("5 >= 15").Compute();

            math = new PostFix(test);
            Assert.AreEqual(0, math.Compute());
        }
Beispiel #2
0
        public void Exponent_Log_Power()
        {
            RPN rpn = new RPN("b^log(b,x)").Compute();

            Assert.AreEqual("x", rpn.Polish.Print());

            rpn.SetEquation("(2x)^log(2x,2)").Compute();
            Assert.AreEqual("2", rpn.Polish.Print());

            rpn.SetEquation("ln(x^2)").Compute();
            Assert.AreEqual("2 x ln *", rpn.Polish.Print());
        }
Beispiel #3
0
        public void DualNumberMultiplication()
        {
            RPN test = new RPN("derivative(2pi,x)").Compute();

            Assert.AreEqual("0", test.Polish.Print());

            test.SetEquation("derivative(2(4),x)").Compute();
            Assert.AreEqual("0", test.Polish.Print());

            test.SetEquation("derivative(pi(2),x)").Compute();
            Assert.AreEqual("0", test.Polish.Print());
        }
Beispiel #4
0
        public void Constants()
        {
            RPN rpn = new RPN("integrate(y,x,a,b)").Compute();

            Assert.AreEqual("y b a - *", rpn.Polish.Print());

            rpn.SetEquation("integrate(sin(y),x,a,b)").Compute();
            Assert.AreEqual("y sin b a - *", rpn.Polish.Print());

            rpn.SetEquation("integrate(sin(y)cos(y),x,a,b)").Compute();
            Assert.AreEqual("y cos y sin * b a - *", rpn.Polish.Print());
        }
Beispiel #5
0
        public void DivisionConstantShared()
        {
            RPN rpn = new RPN("(3x^3)/3").Compute();

            Assert.AreEqual("x 3 ^", rpn.Polish.Print());

            rpn.SetEquation("( (x^3) 3)/3 ").Compute();
            Assert.AreEqual("x 3 ^", rpn.Polish.Print());
        }
Beispiel #6
0
        public void DivisionFlip()
        {
            RPN rpn = new RPN("(5/x)/(x/3)").Compute();

            Assert.AreEqual("5 3 * x 2 ^ /", rpn.Polish.Print());

            rpn.SetEquation("(f/g)/h").Compute();
            Assert.AreEqual("f g h * /", rpn.Polish.Print());
        }
Beispiel #7
0
        public void LnAddOrSub()
        {
            RPN rpn = new RPN("ln(2) + ln(1/3)").Compute();

            Assert.AreEqual("2 3 / ln", rpn.Polish.Print());

            rpn.SetEquation("ln(2) - ln(3)").Compute();
            Assert.AreEqual("2 3 / ln", rpn.Polish.Print());
        }
Beispiel #8
0
        public void GeneralPowerRule()
        {
            RPN test = new RPN("derivative(x^(2x),x)").Compute();

            Assert.AreEqual("x 2 x * ^ 2 x ln * 2 x * x / + *", test.Polish.Print());

            test.SetEquation("derivative(x^x,x)").Compute();
            Assert.AreEqual("x x ^ x ln x x / + *", test.Polish.Print());
        }
Beispiel #9
0
        public void ConstantMultiplications()
        {
            RPN test = new RPN("derivative(2x,x)").Compute();

            Assert.AreEqual("2", test.Polish.Print());

            test.SetEquation("derivative(x2,x)").Compute();
            Assert.AreEqual("2", test.Polish.Print());
        }
Beispiel #10
0
        public void ArcCsc()
        {
            RPN test = new RPN("derivative( arccsc(x), x)").Compute();

            Assert.AreEqual("-1 x abs x 2 ^ 1 - sqrt * /", test.Polish.Print());

            test.SetEquation("derivative( arccsc(x^2), x)").Compute();
            Assert.AreEqual("-2 x * x 2 ^ abs x 4 ^ 1 - sqrt * /", test.Polish.Print());
        }
Beispiel #11
0
        public void ArcCot()
        {
            RPN test = new RPN("derivative( arccot(x), x)").Compute();

            Assert.AreEqual("-1 x 2 ^ 1 + /", test.Polish.Print());

            test.SetEquation("derivative( arccot(x^2), x)").Compute();
            Assert.AreEqual("-2 x * x 4 ^ 1 + /", test.Polish.Print());
        }
Beispiel #12
0
        public void Sin()
        {
            RPN test = new RPN("derivative(sin(x),x)").Compute();

            Assert.AreEqual("x cos", test.Polish.Print());

            test.SetEquation("derivative(sin(x^2),x)").Compute();
            Assert.AreEqual("2 x * x 2 ^ cos *", test.Polish.Print());
        }
Beispiel #13
0
        public void DoubleDerivative()
        {
            RPN test = new RPN("derivative( derivative(x^3,x),x)").Compute();

            Assert.AreEqual("6 x *", test.Polish.Print());

            test.SetEquation("derivative(x^3,x,2)").Compute();
            Assert.AreEqual("6 x *", test.Polish.Print());
        }
Beispiel #14
0
        public void Sqrt()
        {
            RPN test = new RPN("derivative(sqrt(x),x)").Compute();

            Assert.AreEqual("0.5 x sqrt /", test.Polish.Print());

            test.SetEquation("derivative(sqrt(x + 3),x)").Compute();
            Assert.AreEqual("0.5 x 3 + sqrt /", test.Polish.Print());
        }
Beispiel #15
0
        public void Log_Power()
        {
            RPN rpn = new RPN("log(b,1)").Compute();

            Assert.AreEqual("0", rpn.Polish.Print());

            rpn.SetEquation("log(x^2,1)").Compute();
            Assert.AreEqual("0", rpn.Polish.Print());
        }
Beispiel #16
0
        public void Cot()
        {
            RPN rpn = new RPN("cos(x^2)/sin(x^2)").Compute();

            Assert.AreEqual("x 2 ^ cot", rpn.Polish.Print());

            rpn.SetEquation("[(2x) * cos(x^2)]/sin(x^2)").Compute();
            Assert.AreEqual("2 x * x 2 ^ cot *", rpn.Polish.Print());
        }
Beispiel #17
0
        public void SimpleSubtraction()
        {
            RPN rpn = new RPN("solve(x - 2,4)").Compute();

            Assert.AreEqual("x 6 =", rpn.Polish.Print());

            rpn.SetEquation("solve(2 - x,4)").Compute();
            Assert.AreEqual("x -2 =", rpn.Polish.Print());
        }
Beispiel #18
0
        public void SimpleAdd()
        {
            RPN rpn = new RPN("solve(x + 2,4)").Compute();

            Assert.AreEqual("x 2 =", rpn.Polish.Print());

            rpn.SetEquation("solve(2 + x,4)").Compute();
            Assert.AreEqual("x 2 =", rpn.Polish.Print());
        }
Beispiel #19
0
        public void Coefficient()
        {
            RPN rpn = new RPN("integrate(c*x,x,a,b)").Compute();

            Assert.AreEqual("c b 2 ^ a 2 ^ - * 2 /", rpn.Polish.Print());

            rpn.SetEquation("integrate(5*x,x,a,b)").Compute();
            Assert.AreEqual("5 b 2 ^ a 2 ^ - * 2 /", rpn.Polish.Print());
        }
Beispiel #20
0
        public void ListImplicitMultiplication()
        {
            RPN test = new RPN("3{5,2}").Compute();

            Assert.AreEqual("3 5 2 list *", test.Polish.Print());

            test.SetEquation("{5,2}3").Compute();
            Assert.AreEqual("3 5 2 list *", test.Polish.Print());
        }
Beispiel #21
0
        public void LogAddOrSub()
        {
            RPN rpn = new RPN("log(b,R) + log(b,S)").Compute();

            Assert.AreEqual("b R S * log", rpn.Polish.Print());

            rpn.SetEquation("log(b,R) - log(b,S)").Compute();
            Assert.AreEqual("b R S / log", rpn.Polish.Print());
        }
Beispiel #22
0
        public void CosSinToCot()
        {
            RPN rpn = new RPN("cos(x^3)/(x^2 * sin(x^3))").Compute();

            Assert.AreEqual("x 3 ^ cot x 2 ^ /", rpn.Polish.Print());

            rpn.SetEquation("cos(x^3)/(sin(x^3) * x^2)").Compute();
            Assert.AreEqual("x 3 ^ cot x 2 ^ /", rpn.Polish.Print());
        }
Beispiel #23
0
        public void SubtractionCancelation()
        {
            RPN rpn = new RPN("(cos(x)^2)-(-1*(sin(x)^2)) ").Compute();

            Assert.AreEqual("1", rpn.Polish.Print());

            rpn.SetEquation("sin(x) - (-2)").Compute();
            Assert.AreEqual("x sin 2 +", rpn.Polish.Print());
        }
Beispiel #24
0
        public void ZeroMultiplicationDivision()
        {
            RPN rpn = new RPN("0(1/z)").Compute();

            Assert.AreEqual("0 z /", rpn.Polish.Print());

            rpn.SetEquation("(1/z)0").Compute();
            Assert.AreEqual("0 z /", rpn.Polish.Print());
        }
Beispiel #25
0
        public void VariableSubtraction()
        {
            RPN rpn = new RPN("2x - 3x").Compute();

            Assert.AreEqual("-1 x *", rpn.Polish.Print());

            rpn.SetEquation("2x - x").Compute();
            Assert.AreEqual("x", rpn.Polish.Print());
        }
Beispiel #26
0
        public void DoubleTokenize()
        {
            RPN test = new RPN("x * 2").Compute();

            Assert.AreEqual("2 x *", test.Polish.Print());
            Assert.AreEqual(true, test.Data.ContainsVariables);

            test.SetEquation("2x + 2").Compute();
            Assert.AreEqual("2 x * 2 +", test.Polish.Print());
        }
Beispiel #27
0
        public void MixedDivisionMultiplication()
        {
            RPN test = new RPN("1/2x");

            test.Data.ImplicitMultiplicationPriority = true;
            test.Compute();

            Assert.AreEqual("1 2 x * /", test.Polish.Print());

            test.SetEquation("8/2(2 + 2)").Compute();
            Assert.AreEqual("8 2 4 * /", test.Polish.Print());

            test.Data.ImplicitMultiplicationPriority = false;

            test.SetEquation("1/2x").Compute();
            Assert.AreEqual("x 2 /", test.Polish.Print());

            test.SetEquation("8/2(2 + 2)").Compute();
            Assert.AreEqual("16", test.Polish.Print());
        }
Beispiel #28
0
        public void UnaryEOS()
        {
            RPN test = new RPN("-.5 + -.5").Compute();

            PostFix math = new PostFix(test);

            Assert.AreEqual(-1, math.Compute());

            test.SetEquation("-.5 + -.5 ").Compute();
            math = new PostFix(test);
            Assert.AreEqual(-1, math.Compute());
        }
Beispiel #29
0
        public void Equals()
        {
            RPN test = new RPN("30 = 30").Compute();

            PostFix math = new PostFix(test);

            Assert.AreEqual(1, math.Compute());

            test.SetEquation("30 = 29").Compute();

            math = new PostFix(test);
            Assert.AreEqual(0, math.Compute());
        }
Beispiel #30
0
        public void Sin()
        {
            RPN test = new RPN("sin(pi/2)").Compute();

            PostFix math = new PostFix(test);

            Assert.AreEqual(1, math.Compute());

            test.SetEquation("sin(pi)").Compute();

            math = new PostFix(test);
            Assert.AreEqual(0, math.Compute());
        }