Exemplo n.º 1
0
        private Expression ParseExpression()
        {
            var expression = ParseFactor();

            while (true)
            {
                _scanner.SkipWhiteSpace();

                if (_scanner.ReadChar('+'))
                {
                    _scanner.SkipWhiteSpace();

                    expression = new Addition(expression, ParseFactor());
                }
                else if (_scanner.ReadChar('-'))
                {
                    _scanner.SkipWhiteSpace();

                    expression = new Subtraction(expression, ParseFactor());
                }
                else
                {
                    break;
                }
            }

            return(expression);
        }
        public static ICalculable GetOperationClass(ModelCalculator.Operators selectedOperator)
        {
            ICalculable calculateClass = default(ICalculable);

            switch (selectedOperator)
            {
            case ModelCalculator.Operators.Addition:
                calculateClass = new Addition();
                break;

            case ModelCalculator.Operators.Division:
                calculateClass = new Division();
                break;

            case ModelCalculator.Operators.Multiplication:
                calculateClass = new Multiplication();
                break;

            case ModelCalculator.Operators.Subtraction:
                calculateClass = new Subtraction();
                break;

            case ModelCalculator.Operators.SquareRoot:
                calculateClass = new SquareRoot();
                break;
            }

            return(calculateClass);
        }
Exemplo n.º 3
0
        public void Test2()
        {
            var calculation = new Subtraction(10, 10);
            var result      = calculation.Calculate();

            Assert.Equal(0, result);
        }
Exemplo n.º 4
0
        public void CalculateTest()
        {
            var calculator = new Subtraction();
            var actual     = calculator.Calculate(10, 5);

            Assert.AreEqual(5, actual, 0.01);
        }
Exemplo n.º 5
0
        public void DivisionTest(double first, double second, double expected)
        {
            ICalculate calculate = new Subtraction();
            double     result    = calculate.Calculate(first, second);

            Assert.AreEqual(expected, result);
        }
        public void SubtractionResultNotNull()
        {
            Subtraction subt      = new Subtraction();
            int         subAnswer = subt.SubtractionOperation(4, 3);

            Assert.IsNotNull(subAnswer);
        }
Exemplo n.º 7
0
        public void CalculateTest(double firstValue, double secondValue, double expected)
        {
            var calculator   = new Subtraction();
            var actualResult = calculator.Calculator(firstValue, secondValue);

            Assert.AreEqual(expected, actualResult);
        }
Exemplo n.º 8
0
        public void Calcpr()
        {
            var calculator = new Subtraction();
            var actual     = calculator.Calculate(9, 3);

            Assert.AreEqual(6, actual);
        }
        public void SubtractionCalculation()
        {
            Subtraction subt      = new Subtraction();
            int         subAnswer = subt.SubtractionOperation(1, 5);

            Assert.AreEqual(-4, subAnswer);
        }
Exemplo n.º 10
0
        public void SimpleTest(double firstarg, double seconarg, double expected)
        {
            Subtraction calc   = new Subtraction();
            double      result = calc.Calculate(firstarg, seconarg);

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 11
0
        public void isSubtracting()
        {
            var obj = new Subtraction(1.0, 3.0);

            obj.calculate();
            Assert.Equal(obj.result(), -2);
        }
Exemplo n.º 12
0
        public void ZeroBasedMultiplicationRemover_Doesnt_Change_TangentSubtraction()
        {
            var expression = new Subtraction
            {
                Left = new Tangent {
                    Value = 0
                },
                Right = new Constant {
                    Value = 0
                }
            };
            var result = mZeroRemover.Simplify(expression);

            result.Should()
            .BeOfType <Subtraction>()
            .Which.Left.Should()
            .BeOfType <Tangent>()
            .Which.Value.Should()
            .Be(0);
            result.Should()
            .BeOfType <Subtraction>()
            .Which.Right.Should()
            .BeOfType <Constant>()
            .Which.Value.Should()
            .Be(0);
        }
        void HandleSubtractionInAddition(Addition operation, Subtraction chainedOperation)
        {
            var parent = (IArithmeticOperation)chainedOperation.Parent;

            if (mIsRight)
            {
                parent.Left     = chainedOperation.Left;
                operation.Right = new Addition
                {
                    Left = new Subtraction {
                        Left = new Constant {
                            Value = 0
                        }, Right = chainedOperation.Right
                    },
                    Right = operation.Right
                };
            }
            else
            {
                parent.Left = new Subtraction {
                    Left = new Constant {
                        Value = 0
                    }, Right = chainedOperation.Right
                };
                operation.Right = new Addition {
                    Left = chainedOperation.Left, Right = operation.Right
                };
            }
        }
        void HandelSubtractionInSubtraction(Subtraction operation, Subtraction chainedOperation)
        {
            var parent = (IArithmeticOperation)chainedOperation.Parent;

            if (mIsRight)
            {
                parent.Left     = chainedOperation.Left;
                operation.Right = new Subtraction
                {
                    Left = new Subtraction {
                        Left = new Constant {
                            Value = 0
                        }, Right = chainedOperation.Right
                    },
                    Right = operation.Right
                };
                mWasChanged = true;
            }
            else
            {
                parent.Left     = chainedOperation.Right;
                operation.Right = new Subtraction {
                    Left = chainedOperation.Left, Right = operation.Right
                };
                mWasChanged = true;
            }
        }
Exemplo n.º 15
0
        public void Calculate(double firstArgument, double secondArgument, double result)
        {
            var calculator = new Subtraction();
            var testresult = calculator.Calculate(firstArgument, secondArgument);

            Assert.AreEqual(result, testresult);
        }
        void HandelAdditionInSubtraction(Subtraction operation, Addition chainedOperation)
        {
            var parent = (IArithmeticOperation)chainedOperation.Parent;

            if (mIsRight)
            {
                parent.Left = chainedOperation.Left;
                var replacement = new Addition
                {
                    Left  = operation.Left,
                    Right = new Subtraction {
                        Left = chainedOperation.Right, Right = operation.Right
                    }
                };
                CheckForParent(operation, replacement);
                mWasChanged = true;
            }
            else
            {
                parent.Left = chainedOperation.Right;
                var replacement = new Addition
                {
                    Left  = operation.Left,
                    Right = new Subtraction {
                        Left = chainedOperation.Left, Right = operation.Right
                    }
                };
                CheckForParent(operation, replacement);
                mWasChanged = true;
            }
        }
Exemplo n.º 17
0
 public Calculator()
 {
     _operators      = new Dictionary <string, IOperator>();
     _operators["+"] = new Addition();
     _operators["-"] = new Subtraction();
     _operators["*"] = new Multiplication();
 }
Exemplo n.º 18
0
        public void GetSubResults(Subtraction subtraction)
        {
            try
            {
                string[] values     = new string[] { subtraction.Minuend, subtraction.Subtrahend };
                var      allNumbers = CalculatorService.Server.Helpers.Numbers.AllNumbers(values);
                if (allNumbers)
                {
                    var valuesToOperate = CalculatorService.Server.Helpers.Numbers.ConvertStringArrayToDoubleArray(values);
                    // If subtrahend < 0, change it to positive number
                    valuesToOperate[1] = valuesToOperate[1] < 0 ? valuesToOperate[1] * -1 : valuesToOperate[1];

                    double result = valuesToOperate[0] - valuesToOperate[1];

                    subtraction.Total = result;
                }
                else
                {
                    throw new Exception("Some of the elements are not numerics");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public void subtraction(double value01, double value02, double expected)
        {
            Subtraction subtraction       = new Subtraction();
            double      subtractionResult = subtraction.action(value01, value02);

            Assert.Equal(expected, subtractionResult);
        }
Exemplo n.º 20
0
        public void CollectionSizedByExpression2()
        {
            var input = @"
Object1
{
    size : int32;
    size2 : int16;
    collection : bool[size + size2 - 10 * 5];
}";

            var expected = new ProgramBuilder();
            var object1  = expected.AddObject();

            object1.Name = "Object1";
            object1.Fields.Add(("size", new Signed(null, 32), null, null));
            object1.Fields.Add(("size2", new Signed(null, 16), null, null));
            var field3_size = new Subtraction(
                null,
                new Addition(
                    null,
                    new FieldIdentifier(null, "size"),
                    new FieldIdentifier(null, "size2")
                    ),
                new Multiplication(
                    null,
                    new BiPaGe.AST.Literals.Integer(null, "10"),
                    new BiPaGe.AST.Literals.Integer(null, "5")
                    ));

            object1.Fields.Add(("collection", new BiPaGe.AST.FieldTypes.Boolean(null), field3_size, null));
            expected.Validate(SimpleBuilder.Build(input));
        }
Exemplo n.º 21
0
        public IType Visit(Subtraction node)
        {
            var leftHandSideValue  = Visit((dynamic)node.Lhs);
            var rightHandSideValue = Visit((dynamic)node.Rhs);

            return(leftHandSideValue.Subtract(rightHandSideValue));
        }
Exemplo n.º 22
0
        public int Subtract(int a, int b)

        {
            result = Subtraction.Subtract(a, b);

            return(result);
        }
Exemplo n.º 23
0
 public TestBase()
 {
     GivenAdditionOperation       = new Addition();
     GivenSubtractionOperation    = new Subtraction();
     GivenDivisionOperation       = new Division();
     GivenMultyplicationOperation = new Multiplication();
     GivenPowerOperation          = new Power();
 }
        void IExpressionVisitor.Visit(Subtraction subtraction)
        {
            var left  = GetResultFor(subtraction.Left);
            var right = GetResultFor(subtraction.Right);

            Result = UseSubtraction(left, right);
            EvaluatingExpressionVisitor.Steps.Add($"{left}-{right}\n {Result}");
        }
Exemplo n.º 25
0
        public void Subtraction_Works()
        {
            var subtraction = new Subtraction();

            var result = subtraction.Execute(2, 1);

            Assert.AreEqual(1,result);
        }
Exemplo n.º 26
0
        public void TestNoSubtraction()
        {
            Subtraction rule4 = new Subtraction();

            Assert.False(rule4.CheckViolation("CIL"));
            Assert.False(rule4.CheckViolation("MXD"));
            Assert.True(rule4.CheckViolation("XIX"));
        }
Exemplo n.º 27
0
        public void SubtractSymbolForSubtractionShouldBeValid()
        {
            // ReSharper disable once HeapView.ObjectAllocation.Evident
            var        subtraction    = new Subtraction();
            const char subtractSymbol = '-';

            Assert.IsTrue(subtraction.IsValid(subtractSymbol));
        }
Exemplo n.º 28
0
        public void BaseFunctionTest()
        {
            Subtraction sub      = new Subtraction();
            double      expected = 2;
            double      actual   = sub.Execute(4, 2);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 29
0
        public static double ZScore(dynamic score, dynamic values)
        {
            double mean     = StatMean.Mean(values);
            double standDev = StatStandardDev.StandDev(values);
            double zScore   = Division.Quotient(Subtraction.Difference(score, mean), standDev);

            return(zScore);
        }
Exemplo n.º 30
0
        public void NonSubtractSymbolForSubtractionShouldBeInvalid()
        {
            // ReSharper disable once HeapView.ObjectAllocation.Evident
            var        subtraction       = new Subtraction();
            const char nonSubtractSymbol = '/';

            Assert.IsFalse(subtraction.IsValid(nonSubtractSymbol));
        }
Exemplo n.º 31
0
        public void TestSubtractionRule()
        {
            Subtraction rule = new Subtraction();

            Assert.False(rule.Execute("CIL"));
            Assert.False(rule.Execute("MXD"));
            Assert.True(rule.Execute("XIX"));
        }
Exemplo n.º 32
0
        public void calculate_should_return_number_that_is_the_subtraction()
        {
            // Given
            SUT = new Subtraction(new RealNumber(2.0), new RealNumber(6.0));

            // When
            var result = SUT.Calculate() as RealNumber;

            // Then
            Assert.AreEqual(-4.0, result.Value);
        }
Exemplo n.º 33
0
        public void calculate_should_return_real_number_with_subtrted_value()
        {
            // Given
            SUT = new Subtraction(new RealNumber(2.0), new RealNumber(6.0));

            // When
            var result = SUT.Calculate();

            // Then
            Assert.IsInstanceOf<RealNumber>(result);
        }
Exemplo n.º 34
0
 public void Visit(Subtraction sub)
 {
     Visit(sub, OpCodes.Sub_Ovf); // With overflow check
 }
Exemplo n.º 35
0
        //Using this composition of function, that is, first expr and then term ensures that division and multiplication has higher priority over plus and minus.
        private static Sexpr expr(Tokenizer st, Hashtable store)
        {
            Sexpr res = term(st, store);
            st.NextToken();
            while (st.isPlus() || st.isMinus())
            {
                if (st.isPlus())
                {
                    res = new addition(res, term(st,store));
                    st.NextToken();

                }
                else if (st.isMinus())
                {
                    res = new Subtraction(res, term(st, store));
                    st.NextToken();
                }
            }
            st.PushBack();
            return res;
        }
Exemplo n.º 36
0
        public void regenerate_should_regenerate_right_number()
        {
            // Given
            var nbr = new Mock<Number>();
            SUT = new Subtraction(new RealNumber(1), nbr.Object);

            // When
            SUT.Regenerate();

            // Then
            nbr.Verify(x => x.Regenerate());
        }
Exemplo n.º 37
0
 public void Visit(Subtraction sub)
 {
     // Nothing to do here...
 }
Exemplo n.º 38
0
 public void Setup()
 {
     SUT = new Subtraction(new RealNumber(1), new RealNumber(2));
 }
Exemplo n.º 39
0
 public void Visit(Subtraction sub)
 {
     sub.Left.Accept(this);
     _sb.Append("-");
     sub.Right.Accept(this);
 }
Exemplo n.º 40
0
 public void Teardown()
 {
     SUT = null;
 }
Exemplo n.º 41
0
 public void subtractionTest()
 {
     Subtraction MyDifference = new Subtraction();
     int answer = MyDifference.SubtractNum(5, 3);
     Assert.AreEqual(answer, 2);
 }
Exemplo n.º 42
0
 private Expression ParseAdditiveExpression(TokenSet followers) {
   TokenSet followerOrAdditive = followers|Token.Addition|Token.Subtraction;
   Expression result = this.ParseMultiplicativeExpression(followerOrAdditive);
   while (this.currentToken == Token.Addition || this.currentToken == Token.Subtraction) {
     SourceLocationBuilder slb = new SourceLocationBuilder(result.SourceLocation);
     Token operatorToken = this.currentToken;
     this.GetNextToken();
     Expression operand2 = this.ParseMultiplicativeExpression(followerOrAdditive);
     slb.UpdateToSpan(operand2.SourceLocation);
     switch (operatorToken) {
       case Token.Addition: result = new Addition(result, operand2, slb); break;
       case Token.Subtraction: result = new Subtraction(result, operand2, slb); break;
     }
   }
   //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile;
   return result;
 }
Exemplo n.º 43
0
 public void Visit(Subtraction sub)
 {
     ResultIsIntAndBothOperandsMustBeInt(sub);
 }
Exemplo n.º 44
-1
        public void constructor_should_set_right_number()
        {
            // Given
            var nbr = new Variable("a", new RealNumber(1));

            // When
            SUT = new Subtraction(new Variable("b", new RealNumber(1)), nbr);

            // Then
            Assert.AreSame(nbr, SUT.RightSide);
        }