public void Parse_X_WithNumbers() { //Arrange var text = "2*x+1"; var expected = "2x*1+"; //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, expected)); }
public void Add_TwoTwoDigitIntegers() { //Arrange var text = "12 + 13"; var expected = " 12 13 +"; //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, expected)); }
public void Parse_Number_Subtract_X() { //Arrange var text = "1-x"; var expected = "1x-"; //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, expected)); }
public void Parse_e_Sin() { //Arrange var text = "Sin(e)"; var expected = Constants.e + " sin"; //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, expected)); }
public void AddThenMultiplyThenPower() { //Arrange var text = "2 + 3 * 4 ^ 1"; var output = " 2 3 4 1 ^ * +"; //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, output)); }
public void Parse_EM() { //Arrange var text = "em"; var expected = Constants.EM.ToString(); //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, expected)); }
public void Parse_Parenthesis() { //Arrange var text = "(3 + x)-2"; var expected = "3 x + 2 -"; //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, expected)); }
public void Add_TwoFloatingNumbers() { //Arrange var text = 12.5.ToString() + "+" + 13.5.ToString(); var expected = 12.5.ToString() + 13.5.ToString() + "+"; //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, expected)); }
public void Parse_RecognizesImaginary() { //Arrange var text = "1 + i"; var expected = "1i+"; //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, expected)); Assert.IsTrue(rpn.Output[1].Type == SymbolTypes.Imaginary); }
public void Divide_x_by_x() { //Arrange var text = "x/x"; var expected = RPNParser.Parse("1"); //Act var rpn = RPNParser.Parse(text); var actual = RPNParser.Parse(ExpressionBuilder.BuildFlat(rpn.Output).Execute().ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output)); }
public void Add_x_y_fun() { //Arrange var text = "x + x + y + fun + fun"; var expected = RPNParser.Parse("2*fun + 2*x + y"); //Act var rpn = RPNParser.Parse(text); var actual = RPNParser.Parse(ExpressionBuilder.BuildFlat(rpn.Output).Execute().ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output)); }
public void Parse_Log() { //Arrange var text = "Log(" + 3.14m.ToString() + ")"; var expected = 3.14m.ToString() + " log"; //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, expected)); Assert.IsTrue(rpn.Output[1].Type == SymbolTypes.Function); }
public void Parse_FunctionInCorrrectOrder() { //Arrange var text = "Cos(x)-2"; var expected = "x cos 2 -"; //Act var rpn = RPNParser.Parse(text); //Assert Assert.IsTrue(RPNComparer.Compare(rpn.Output, expected), $"Expected: {expected} but was {string.Join(" ", rpn.Output.Select(x => x.Value))}"); Assert.IsTrue(rpn.Output[1].Type == SymbolTypes.Function); }
public void Power_xy2() { //Arrange var text = "x*y^2"; var expected = RPNParser.Parse("x*y*y"); //Act var rpn = RPNParser.Parse(text); var actual = RPNParser.Parse(ExpressionBuilder.BuildFlat(rpn.Output).Execute().ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output)); }
public void VariableWithAddAndDivide() { //Arrange var text = "2*x + 7 -2 + 2*x*x/x"; //+ 2*x*x/x var expected = RPNParser.Parse("4*x + 5"); //Act var rpn = RPNParser.Parse(text); var the = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(ExpressionBuilder.BuildFlat(rpn.Output).Execute().ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(actual.Output, expected.Output)); }
public void Add_FlatAdd_Variable() { //Arrange var text = "2 + x + x^2 + x"; var expected = RPNParser.Parse("x*x + 2*x + 2"); //Act var rpn = RPNParser.Parse(text); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output)); }
public void VariableWithFunction() { //Arrange var test = "Sin(x) + x + Sin(x)"; var expText = "2 * Sin(x) + x"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(test); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Multiply_FlatMult_FlatThatIsZero() { //Arrange var text = "x*(x -x)"; var expText = "0"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(text); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(ExpressionBuilder.BuildFlat(rpn.Output).Execute().ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Multiply_FlatAdd_Number() { //Arrange var test = "(2 + x)*2"; var expText = "2*(2 + x)"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(test); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Add_FlatAdd_Sinx_CTan2x() { //Arrange var test = "Sin(x) + 2 + x + Cot(2*x)"; var expText = "x + 2 + Sin(x) + Cot(2*x)"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(test); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Multiply_Sin_Sin_x() { //Arrange var text = "Sin(x)*Sin(x)*x"; var expText = "x*(Sin(x))^2"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(text); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Squash_To_Quadratic() { //Arrange var text = "2 * x * x + 5 + 3 * x - 1";// "2 * x - 1 + 3 * x * x + x + 5 - x*x"; var expText = "2 * x * x + 3 * x + 4"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(text); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Add_Different_FlatMultiply() { //Arrange var text = "y * 2 * x + 3 * x * y + x + y"; var expText = " 5 * x * y + x + y"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(text); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Pow_1() { //Arrange var text = "(2+x)^1"; var expText = "2+x"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(text); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Divide_x_by_x_by_y_() { //Arrange var text = "x/(x/y)"; var expText = "1*y"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(text); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Add_FlatAddReal_FlatAddImagined_TheSame() { //Arrange var test = "2 + x + i * (x + 2)"; var expText = " 2 + 2 * i(1 + i) * x"; // "(2 + x) * (1 + i)"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(test); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Value_Squash_TwoVariables() { //Arrange var text = "y * 2 * x * 3 * x * y * y"; var expText = "6 * (y)^3 * (x)^2"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(text); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Squash_OneVariable() { //Arrange var test = "2 * x * 3 * x"; var expText = "( 6 * x * x)"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(test); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Power_2On_FlatAdd_x_y() { //Arrange var text = "(x+y)^2"; //var expText = "x*x + 2*x*y + y*y"; var expText = "(x+y)^2"; var expected = RPNParser.Parse(expText); //Act var rpn = RPNParser.Parse(text); var expr = ExpressionBuilder.BuildFlat(rpn.Output).Execute(); var actual = RPNParser.Parse(expr.ToString()); //Assert Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {expr.ToString()}"); }
public void Linear_WithVariable_3() { //Arrange var text = "y*x - 4 + z"; var expText = "(4 - z)/y"; var expected = RPNParser.Parse(expText); var expression = ExpressionBuilder.BuildFlat(RPNParser.Parse(text).Output).Execute(); var equation = new Equation(text, expression, null); //Act var sut = Solver.Solve(equation, "x"); var actual = RPNParser.Parse(sut.Solutions["x"].Item2[0].ToString()); //Assert Assert.IsTrue(sut.Solutions.Count == 1); Assert.IsTrue(RPNComparer.Compare(expected.Output, actual.Output), $"Expected: {expText} but was {sut.Solutions["x"].Item2[0].ToString()}"); }