public void SumExpressionInterpretForTwoVariablesReturnsTheirSum() { IExpression left = new VariableX(); IExpression right = new VariableX(); SumExpression sum = new SumExpression(left, right); Context context = new Context(4); Assert.AreEqual(8, sum.Interpret(context)); }
public void SumExpressionInterpretForConstantsAndVariableReturnsTheirSum() { IExpression left = new VariableX(); IExpression right = new Constant("2"); SumExpression sum = new SumExpression(left, right); Context context = new Context(3); Assert.AreEqual(5, sum.Interpret(context)); }
public void SumExpressionInterpretForTwoConstantsReturnsTheirSum() { Constant left = new Constant("23"); Constant right = new Constant("2"); SumExpression sum = new SumExpression(left, right); Context context = new Context(3); Assert.AreEqual(25, sum.Interpret(context)); }
public void MathFunctionReturnsValueAndCalculatesTheSentenceWithUnknown3() { // 2 + atan(x) + x IExpression two = new Constant(2); string function = "ata(x)"; FunctionConverter f = new FunctionConverter(); IExpression value = new VariableX(); IExpression mathFun = new MathFunction(f.Translator(function), value); IExpression x = new VariableX(); IExpression result = new SumExpression(two, mathFun); result = new SumExpression(result, x); Context c = new Context(1); var y = result.Interpret(c); Assert.AreEqual(3.785, y, 4); }
public void MathFunctionReturnsValueAndCalculatesTheSentenceWithFunLog2() { // 2 + cos(-123) + x IExpression two = new Constant(2); string function = "cos(-123)"; FunctionConverter f = new FunctionConverter(); IExpression value = new Constant(f.getValue(function)); IExpression mathFun = new MathFunction(f.Translator(function), value); IExpression x = new VariableX(); IExpression result = new SumExpression(two, mathFun); result = new SumExpression(result, x); Context c = new Context(123); var y = result.Interpret(c); Assert.AreEqual(124.45, y, 2); }