public void TestPenjumlahan() { var statement = "2+5"; var calc = new Jace.CalculationEngine(); Assert.AreEqual(7, calc.Calculate(statement)); }
public void Test_IIF_Function() { var calc = new Jace.CalculationEngine(); calc.AddFunction("iif", (a, b, c) => a != 0.0? b: c); var statementFalse = "iif(0,1,2)"; Assert.AreEqual(2, calc.Calculate(statementFalse)); var statementTrue = "iif(1,1,2)"; Assert.AreEqual(1, calc.Calculate(statementTrue)); Dictionary <string, double> attandance = new Dictionary <string, double>(); attandance.Add("Regular", 1); var statementAttTrue = "iif(Regular==1,1,2)"; Assert.AreEqual(1, calc.Calculate(statementAttTrue, attandance)); attandance.Clear(); attandance.Add("Regular", 0); var statementAttFalse = "iif(Regular==1,1,2)"; Assert.AreEqual(2, calc.Calculate(statementAttFalse, attandance)); }
public void TestIfStatement() { Dictionary <string, double> attandance = new Dictionary <string, double>(); attandance.Add("OTHour", 1); attandance.Add("OT", 1); var statement = "if(OTHour==OT,1,2)"; var calc = new Jace.CalculationEngine(); Assert.AreEqual(1, calc.Calculate(statement, attandance)); }
public void TestCalculateFromVariableOnly() { Dictionary <string, double> attandance = new Dictionary <string, double>(); attandance.Add("OTHour", 4); attandance.Add("OT1", 2); var calc = new Jace.CalculationEngine(); var statement = "OTHour*OT1"; Assert.AreEqual(8, calc.Calculate(statement, attandance)); }
public void TestDate1GreaterThanDate2() { var date1 = new DateTime(2020, 1, 13).Ticks; var date2 = new DateTime(2020, 1, 12).Ticks; Dictionary <string, double> variables = new Dictionary <string, double>(); variables.Add("date1", date1); variables.Add("date2", date2); var statement = "if(DateDiff(date1,date2)==-1,1,0)"; var calc = new Jace.CalculationEngine(); calc.AddFunction("DateDiff", (a, b) => a < b ? -1 : a == b ? 0 : 1); Assert.AreEqual(0, calc.Calculate(statement, variables)); }
public void Test_IIF_Function_with_and_operator() { var calc = new Jace.CalculationEngine(); calc.AddFunction("iif", (a, b, c) => a != 0.0 ? b : c); Dictionary <string, double> attandance = new Dictionary <string, double>(); attandance.Add("Regular", 1); attandance.Add("Remark", 1); attandance.Add("AL", 1); var statementAttTrue = "iif(Regular==1 && Remark==AL,1,2)"; Assert.AreEqual(1, calc.Calculate(statementAttTrue, attandance)); attandance["Remark"] = 0; var statementAttFalse = "iif(Regular==1 && Remark==AL,1,2)"; Assert.AreEqual(2, calc.Calculate(statementAttFalse, attandance)); }