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)); } }
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)); } }
/* 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); }
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())); }
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())); }
public void TestEquationDzielenie() { string equation = " 8 / 2 "; ONP OnpMock = new ONP(equation); Decimal expected = new Decimal(4); Assert.AreEqual(expected, Decimal.Parse(OnpMock.ONPCalculationResult())); }
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())); }
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())); }
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)); }
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)); }
private static void Main() { int remainingTestCases = int.Parse(Console.ReadLine()); while (remainingTestCases-- > 0) { Console.WriteLine( ONP.Solve(Console.ReadLine())); } }
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)); } }; }