public override string ToString() { // one of base numbers if (operand == MyNumberOperators.NONE) { return(currentValue.ToString()); } char c = operatorChars[(short)operand]; if (operand == MyNumberOperators.SUB && right.HasSubOperand()) { return(string.Format("{0} {1} ({2})", left.ToString(), c, right.ToString())); } else if (operand == MyNumberOperators.MULTIPLY || operand == MyNumberOperators.DIVIDE) { if (left.operand == MyNumberOperators.ADD || left.operand == MyNumberOperators.SUB) { if (right.operand == MyNumberOperators.ADD || right.operand == MyNumberOperators.SUB) { return(string.Format("({0}) {1} ({2})", left.ToString(), c, right.ToString())); } else { return(string.Format("({0}) {1} {2}", left.ToString(), c, right.ToString())); } } else if (right.operand == MyNumberOperators.ADD || right.operand == MyNumberOperators.SUB) { return(string.Format("{0} {1} ({2})", left.ToString(), c, right.ToString())); } } return(string.Format("{0} {1} {2}", left.ToString(), c, right.ToString())); }
public void FindSolution_ShouldReturnResult(int number, int[] numbers, string expression, int result) { MyNumberItem myItem = engine.FindSolution(number, numbers); Assert.IsNotNull(myItem); Assert.AreEqual(result, myItem.currentValue); Assert.AreEqual(expression, myItem.ToString()); }