Exemple #1
0
        /* Przekazuje dzialanie do obliczenia */
        public void ExecuteCalculations()
        {
            string tempTODELETE = CurrentEquationState;

            if (NumberBaseSystem.Decimal != CurrentNumberBaseSystem)
            {
                string[] parsedEquation = CurrentEquationState.ParseEquation();
                AnalyzeParsedEquation(parsedEquation);
            }

            ONP myONP = new ONP(CurrentEquationState);

            CurrentEquationState = myONP.ONPCalculationResult();

            /* W przypadku bledu we wprowadzonym dzialaniu wyslij eventa (GUI go odbiera i wyswietla) */
            if (CurrentEquationState == "ERROR")
            {
                ErrorOccurred(this, new MyEventArgs("Blad we wprowadzonym dzialaniu!"));
                CurrentEquationState = "0";
            }
            else
            {
                CutDecimalPortion();
                // ewentualne skrocenie liczby gdyby byla za duza dla danego rozmiaru slowa
                TrimOutcomeNumber();
                ChangeNumberBaseSystem(CurrentEquationState, NumberBaseSystem.Decimal, CurrentNumberBaseSystem);
            }
            ChangeWordButton(this, new MyEventArgs("true"));
            UpdateDisplay(this, eUpdateArgs);
        }
Exemple #2
0
        public void TestEquation1()
        {
            string  equation = " 2 + 3 * 6 - 8 / 4 ";
            ONP     OnpMock  = new ONP(equation);
            Decimal expected = new Decimal(18);

            Assert.AreEqual(expected, Decimal.Parse(OnpMock.ONPCalculationResult()));
        }
Exemple #3
0
        public void TestEquationNawiasPotega()
        {
            string  equation = " ( 2 + 2 ) ^ 2 ";
            ONP     OnpMock  = new ONP(equation);
            Decimal expected = new Decimal(16);

            Assert.AreEqual(expected, Decimal.Parse(OnpMock.ONPCalculationResult()));
        }
Exemple #4
0
        public void TestEquationDzielenie()
        {
            string  equation = " 8 / 2 ";
            ONP     OnpMock  = new ONP(equation);
            Decimal expected = new Decimal(4);

            Assert.AreEqual(expected, Decimal.Parse(OnpMock.ONPCalculationResult()));
        }
Exemple #5
0
        public void TestEquation3()
        {
            string  equation = " ( 8 + 8 )  * (2 + 2) * 6 - 6 / 2 ^ 2 ";
            ONP     OnpMock  = new ONP(equation);
            Decimal expected = new Decimal(382.5);

            Assert.AreEqual(expected, Decimal.Parse(OnpMock.ONPCalculationResult()));
        }
Exemple #6
0
        public void TestEquation2()
        {
            string  equation = " ( 8 + 9 ) / (2 + 2) * (2 + 3) * 6 - 8 / 4 ";
            ONP     OnpMock  = new ONP(equation);
            Decimal expected = new Decimal(125.5);

            Assert.AreEqual(expected, Decimal.Parse(OnpMock.ONPCalculationResult()));
        }
Exemple #7
0
        public void TestModuloAlone()
        {
            string  equation  = " 2 % 8 ";
            ONP     OnpMock   = new ONP(equation);
            Decimal expected  = new Decimal(2);
            string  onpResult = OnpMock.ONPCalculationResult();

            Assert.AreEqual(expected, Decimal.Parse(onpResult));
        }
Exemple #8
0
        public void TestModuloAlone2()
        {
            Console.WriteLine("2 mod 2 = " + 2 % 2 + " expected = 1");
            string  equation  = " 2 % 2 ";
            ONP     OnpMock   = new ONP(equation);
            Decimal expected  = new Decimal(0);
            string  onpResult = OnpMock.ONPCalculationResult();

            Assert.AreEqual(expected, Decimal.Parse(onpResult));
        }