Exemple #1
0
		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);
		}
Exemple #2
0
		public void Calculate_ValidOperationString_ReturnsAnswer1()
		{
			var calc = new Calculator();
			var result = calc.Calculate("3+2");
			var expectation = 5;
			Assert.AreEqual(expectation, result);
		}
Exemple #3
0
        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();
        }
Exemple #4
0
 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()));
 }
Exemple #5
0
 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()));
 }
Exemple #6
0
 public void OperationToElements_invalidOperationString_ThrowsIncorrectOperationStringException()
 {
     var calc = new Calculator();
     Assert.Throws<IncorrectOperationStringException>(() => calc.OperationToElements("2!2"));
 }
Exemple #7
0
 public void Calculate_EmptyString_ThrowsEmptyStringException()
 {
     var calc = new Calculator();
     Assert.Throws<EmptyStringException>(() => calc.Calculate(""));
 }