Example #1
0
        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);
        }
Example #2
0
        /* 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);
        }
Example #3
0
        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());
        }
Example #4
0
        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());
        }