Пример #1
0
        /// <summary>
        /// <para>
        /// To determine the sequence of actions: execution priority is medium
        /// </para>
        /// <para>
        /// Medium priority operations: multiplication, division, moduloDivision
        /// </para>
        /// </summary>
        private UniversalOperation ParsingAnExpression_MediumPriority()
        {
            UniversalOperation result = ParsingAnExpression_HighPriority();

            while (true)
            {
                //You can use this for multiplicatio, division, moduloDivision

                if (MatchSearch('×') || MatchSearch('*'))
                {
                    result = new Multiply(result, ParsingAnExpression_HighPriority());
                }
                else if (MatchSearch('%'))
                {
                    result = new ModuleDivision(result, ParsingAnExpression_HighPriority());
                }
                else if (MatchSearch('÷'))
                {
                    result = new Division(result, ParsingAnExpression_HighPriority());
                }

                /*else if(MatchSearch('¹'))
                 * {
                 *  result = new PartOfTheWhole(result, ParsingAnExpression_HighPriority());
                 * }*/
                else
                {
                    return(result);
                }
            }
        }
        public void ModuloDivisionNegativeIntegerNumberOnZeroOne()
        {
            Number leftArg  = new Number(-50m);
            Number rightArg = new Number(0m);

            ModuleDivision mod = new ModuleDivision(leftArg, rightArg);

            Assert.ThrowsException <DivideByZeroException>(() => mod.Operation());
        }
        public void ModuloDivisionPositiveRealNumberOnZeroOne()
        {
            Number leftArg  = new Number(100.1m);
            Number rightArg = new Number(0m);

            ModuleDivision mod = new  ModuleDivision(leftArg, rightArg);

            Assert.ThrowsException <DivideByZeroException>(() => mod.Operation());
        }
        public void ModuloDivisionZeroNumberOnPositiveRealOne()
        {
            Number  leftArg  = new Number(0m);
            Number  rightArg = new Number(7.4m);
            decimal expected = 0m;

            ModuleDivision div    = new ModuleDivision(leftArg, rightArg);
            decimal        actual = div.Operation();

            Assert.AreEqual(expected, actual);
        }
        public void ModuloDivisionPositiveIntegerNumberOnNegativeRealOne()
        {
            Number  leftArg  = new Number(17m);
            Number  rightArg = new Number(-7.2m);
            decimal expected = 2.6m;

            ModuleDivision div    = new ModuleDivision(leftArg, rightArg);
            decimal        actual = div.Operation();

            Assert.AreEqual(expected, actual);
        }
        public void ModuloDivisionNegativeIntegerNumberOnPositiveIntegerOne()
        {
            Number leftArg  = new Number(-78m);
            Number rightArg = new Number(33m);
            int    expected = -12;

            ModuleDivision div    = new ModuleDivision(leftArg, rightArg);
            decimal        actual = div.Operation();

            Assert.AreEqual(expected, actual);
        }
Пример #7
0
        /// <summary>
        /// <para>
        /// To determine the sequence of actions: execution priority is medium
        /// </para>
        /// <para>
        /// Medium priority operations: multiplication, division, moduloDivision
        /// </para>
        /// </summary>
        private UniversalOperation ParsingAnExpression_MediumPriority()
        {
            UniversalOperation result = ParsingAnExpression_HighPriority();

            while (true)
            {
                if (MatchSearch('*'))
                {
                    result = new Multiplication(result, ParsingAnExpression_HighPriority());
                }
                else if (MatchSearch('%'))
                {
                    result = new ModuleDivision(result, ParsingAnExpression_HighPriority());
                }
                else if (MatchSearch('/') || MatchSearch('÷'))
                {
                    result = new Division(result, ParsingAnExpression_HighPriority());
                }
                else
                {
                    return(result);
                }
            }
        }