private static string PrintNodes(EquationStruct node, string indentation, bool isRightOperand) { string eq = indentation + "+- {" + node.GetOperator() + "}"; if (node.GetLeftOperand() == null && node.GetRightOperand() == null) { eq += " " + node.GetVariableName(); } if (isRightOperand && node.GetLeftOperand() == null && node.GetRightOperand() == null) { indentation += " "; } else { indentation += "| "; } eq += System.Environment.NewLine; if (node.GetLeftOperand() != null) { eq += PrintNodes(node.GetLeftOperand(), indentation, false); } if (node.GetRightOperand() != null) { eq += PrintNodes(node.GetRightOperand(), indentation, true); } return(eq); }
public void TestEqSetLeftOperand() { // unittest-equationdatastructuresetleftop EquationStruct eq = new EquationStruct("+", "x", null, null); eq.SetLeftOperand(new EquationStruct("VAR", "y", null, null)); Assert.AreEqual("y", eq.GetLeftOperand().GetVariableName()); }
/* HELPER FUNCTIONS */ private static string PrintEquation(EquationStruct node) { string equation = ""; if (node.GetLeftOperand() == null) { equation = node.GetOperator() + ": " + node.GetVariableName(); } else if (node.GetRightOperand() == null) { equation = node.GetOperator() + "(" + PrintEquation(node.GetLeftOperand()) + ")"; } else { equation = node.GetOperator() + "(" + PrintEquation(node.GetLeftOperand()) + ", " + PrintEquation(node.GetRightOperand()) + ")"; } return(equation); }
public void TestEquationStructConstructor() { // unittest-equationdatastructureconstruct EquationStruct eq = new EquationStruct("+", "x", new EquationStruct("VAR", "y", null, null), new EquationStruct("VAR", "z", null, null)); Assert.AreEqual("+", eq.GetOperator()); Assert.AreEqual("x", eq.GetVariableName()); Assert.AreEqual("y", eq.GetLeftOperand().GetVariableName()); Assert.AreEqual("z", eq.GetRightOperand().GetVariableName()); }
public void TestEquationStructConstructorWithNulls() { // unittest-equationdatastructureconstructnulls EquationStruct eq = new EquationStruct("+", "x", null, null); Assert.AreEqual("+", eq.GetOperator()); Assert.AreEqual("x", eq.GetVariableName()); Assert.AreEqual(null, eq.GetLeftOperand()); Assert.AreEqual(null, eq.GetRightOperand()); }