private Operand Subtract(string p1, string p2)
        {
            var fraction  = Operand.Parse(p1);
            var fraction2 = Operand.Parse(p2);
            var sut       = new SubtractOperator();

            return(sut.Solve(fraction, fraction2));
        }
Exemple #2
0
        public override VariableValue Evaluate(IVariableStore variables)
        {
            var left   = Left.Evaluate(variables);
            var right  = Right.Evaluate(variables);
            var result = SubtractOperator.Subtract(ref left, ref right);

            return(Assign(variables, ref result));
        }
Exemple #3
0
        public void SubtractOperatorTest()
        {
            string path = @"subtracttest.txt";

            File.WriteAllText(path, "8\n3");
            SubtractOperator subtract = new SubtractOperator(File.OpenText(path));

            Assert.AreEqual(subtract.Evaluate(), 5);
            Assert.AreEqual(subtract.ToString(), "(8-3)");
        }
        public void TestBuildExpressionForUnaryWithRightHandExpression()
        {
            var op = new SubtractOperator();

            var expression = op.BuildExpression(
                new Token("+", 1),
                new[]
            {
                null,
                Mock.Of <IExpression>(e => e.Evaluate(It.IsAny <IDictionary <string, object> >()) == (object)null)
            },
                ExpressiveOptions.None);

            Assert.IsInstanceOfType(expression, typeof(MinusExpression));
        }
        public void TestGetPrecedenceForBinary()
        {
            var op = new SubtractOperator();

            Assert.AreEqual(OperatorPrecedence.Subtract, op.GetPrecedence(new Token("1", 1)));
        }
        public void TestGetPrecedenceForUnary()
        {
            var op = new SubtractOperator();

            Assert.AreEqual(OperatorPrecedence.UnaryMinus, op.GetPrecedence(null));
        }