Exemplo n.º 1
0
        public IActionResult Get(string formula, double from, double to, int n)
        {
            ONP test = new ONP(formula);

            string[] infix = test.Tokeny(test.Wejscie);
            if (!test.Sprawdzenie(infix))
            {
                var data = new
                {
                    status  = "error",
                    message = "invalid formula"
                };
                return(BadRequest(data));
            }
            else
            {
                List <string> postfix = test.Zamiana(infix);
                double[,] wyniki = test.ObliczaniePrzedzialow(postfix, from, to, n);
                var data = new
                {
                    status = "ok",
                    result = new
                    {
                        x = "???",
                        y = "???"
                    }
                };
                return(Ok(data));
            }
        }
Exemplo n.º 2
0
        public IActionResult Get(string formula)
        {
            ONP test = new ONP(formula);

            string[] infix = test.Tokeny(test.Wejscie);
            if (!test.Sprawdzenie(infix))
            {
                var data = new
                {
                    status  = "blad",
                    message = "niepoprawna formula"
                };
                return(BadRequest(data));
            }
            else
            {
                List <string> postfix = test.Zamiana(infix);
                var           data    = new
                {
                    status = "ok",
                    result = new
                    {
                        infix = infix,
                        rpn   = postfix
                    }
                };
                return(Ok(data));
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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()));
        }
Exemplo n.º 5
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()));
        }
Exemplo n.º 6
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()));
        }
Exemplo n.º 7
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()));
        }
Exemplo n.º 8
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()));
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
0
    private static void Main()
    {
        int remainingTestCases = int.Parse(Console.ReadLine());

        while (remainingTestCases-- > 0)
        {
            Console.WriteLine(
                ONP.Solve(Console.ReadLine()));
        }
    }
Exemplo n.º 12
0
        public IActionResult Get(string formula, double x)
        {
            ONP test = new ONP(formula);

            test.Zmienna = x;
            string[] infix = test.Tokeny(test.Wejscie);
            if (!test.Sprawdzenie(infix))
            {
                var data = new
                {
                    status  = "error",
                    message = "invalid formula"
                };
                return(BadRequest(data));
            }
            else
            {
                List <string> postfix = test.Zamiana(infix);
                try
                {
                    var data = new
                    {
                        status = "ok",
                        result = test.ObliczaniePostfixa(postfix)
                    };
                    return(Ok(data));
                }
                catch (Exception)
                {
                    var data = new
                    {
                        status  = "error",
                        message = "niepoprawna dziedzina funkcji"
                    };
                    return(BadRequest(data));
                }
            };
        }