public void Calculate_ValidOperationString_ReturnsAnswer2() { var calc = new Calculator(); var result = calc.Calculate("((2+7)/3+(14-3)*4)/2"); var expectation = 23.5; Assert.AreEqual(expectation, result); }
public void Calculate_ValidOperationString_ReturnsAnswer1() { var calc = new Calculator(); var result = calc.Calculate("3+2"); var expectation = 5; Assert.AreEqual(expectation, result); }
static void Main() { Calculator calc = new Calculator(); Console.WriteLine(calc.Calculate("((2+7)/3+(14-3)*4)/2")); Console.WriteLine(calc.Calculate("((2+7)/3+(14-3)*4)")); Console.ReadLine(); }
public void OperationToElements_validOperationString_ElementsInQueue() { var calc = new Calculator(); var result = calc.OperationToElements("3+2"); var expectation = new Queue<OperationElement>(); expectation.Enqueue(new OperationElement(OperationElementType.NUMBER,"3")); expectation.Enqueue(new OperationElement(OperationElementType.OPERATOR, "+")); expectation.Enqueue(new OperationElement(OperationElementType.NUMBER, "2")); Assert.AreEqual(expectation.Select(r => r.ToTestValue()), result.Select(r => r.ToTestValue())); }
public void OperationElementsToONP_validOperationElements_ElementsInONPQueue2() { var calc = new Calculator(); var operationElements = new Queue<OperationElement>(); operationElements = calc.OperationToElements("2+3*5"); var expectation = new Queue<OperationElement>(); expectation.Enqueue(new OperationElement(OperationElementType.NUMBER, "2")); expectation.Enqueue(new OperationElement(OperationElementType.NUMBER, "3")); expectation.Enqueue(new OperationElement(OperationElementType.NUMBER, "5")); expectation.Enqueue(new OperationElement(OperationElementType.OPERATOR, "*")); expectation.Enqueue(new OperationElement(OperationElementType.OPERATOR, "+")); var result = calc.OperationElementsToONP(operationElements); Assert.AreEqual(expectation.Select(r => r.ToTestValue()), result.Select(r => r.ToTestValue())); }
public void OperationToElements_invalidOperationString_ThrowsIncorrectOperationStringException() { var calc = new Calculator(); Assert.Throws<IncorrectOperationStringException>(() => calc.OperationToElements("2!2")); }
public void Calculate_EmptyString_ThrowsEmptyStringException() { var calc = new Calculator(); Assert.Throws<EmptyStringException>(() => calc.Calculate("")); }