public void TestMethodLiteralVariableMultiVariable() { var variableDataTypeMap = new Dictionary <string, DataType>(); variableDataTypeMap.Add("testVariable1", DataType.Boolean); variableDataTypeMap.Add("testVariable2", DataType.Integer); variableDataTypeMap.Add("testVariable3", DataType.Decimal); var variableMap = new Dictionary <string, Variable>(); variableMap.Add("testVariable1", new Variable(true)); variableMap.Add("testVariable2", new Variable(222)); variableMap.Add("testVariable3", new Variable(333.33)); var literalVariable = new LiteralVariable(); literalVariable.value = "testVariable1"; Assert.AreEqual("Var[testVariable1]", literalVariable.getRPolish()); Assert.AreEqual(DataType.Boolean, literalVariable.getDataType(variableDataTypeMap)); UnitTestUtil.AssertMathTreeNodeValue(true, literalVariable.eval(variableMap)); literalVariable.value = "testVariable2"; Assert.AreEqual("Var[testVariable2]", literalVariable.getRPolish()); Assert.AreEqual(DataType.Integer, literalVariable.getDataType(variableDataTypeMap)); UnitTestUtil.AssertMathTreeNodeValue(222, literalVariable.eval(variableMap)); literalVariable.value = "testVariable3"; Assert.AreEqual("Var[testVariable3]", literalVariable.getRPolish()); Assert.AreEqual(DataType.Decimal, literalVariable.getDataType(variableDataTypeMap)); UnitTestUtil.AssertMathTreeNodeValue(333.33, literalVariable.eval(variableMap)); }
public void TestMethodLiteralVariableNoMatch() { var variableDataTypeMap = new Dictionary <string, DataType>(); variableDataTypeMap.Add("testVariable1", DataType.Boolean); variableDataTypeMap.Add("testVariable2", DataType.Integer); variableDataTypeMap.Add("testVariable3", DataType.Decimal); var variableMap = new Dictionary <string, Variable>(); variableMap.Add("testVariable1", new Variable(true)); variableMap.Add("testVariable2", new Variable(222)); variableMap.Add("testVariable3", new Variable(333.33)); var literalVariable = new LiteralVariable(); literalVariable.value = "testVariable"; Assert.AreEqual("Var[testVariable]", literalVariable.getRPolish()); Assert.AreEqual(DataType.None, literalVariable.getDataType(variableDataTypeMap)); try { literalVariable.eval(variableMap); Assert.Fail(); } catch (Exception e) { Assert.IsTrue(e.GetType() == typeof(ArgumentException)); } }
public void TestMethodLiteralVariableBoolean() { var variableDataTypeMap = new Dictionary <string, DataType>(); variableDataTypeMap.Add("testVariable", DataType.Boolean); var variableMap = new Dictionary <string, Variable>(); variableMap.Add("testVariable", new Variable(true)); var literalVariable = new LiteralVariable(); literalVariable.value = "testVariable"; Assert.AreEqual("Var[testVariable]", literalVariable.getRPolish()); Assert.AreEqual(DataType.Boolean, literalVariable.getDataType(variableDataTypeMap)); UnitTestUtil.AssertMathTreeNodeValue(true, literalVariable.eval(variableMap)); }