public void equation_with_variable_and_null_argument() { var formula = new Formula("a+5"); formula.IsValid.ShouldBeTrue(); Assert.Throws<MathException>(() => formula.Evaluate()); }
public void invalid_formula_bracket_closed_before_opened() { var formula = new Formula(")5 + 7(*5"); formula.IsValid.ShouldBeFalse(); Assert.Throws<MathException>(() => formula.Evaluate()); }
public void equation_with_two_variables_and_argument_with_one_value() { var formula = new Formula("a*(5-b)"); formula.IsValid.ShouldBeTrue(); Assert.Throws<MathException>(() => formula.Evaluate(new { a = 7 })); }
public void equation_with_variable() { var formula = new Formula("a+5"); formula.IsValid.ShouldBeTrue(); formula.Evaluate(new { a = 7 }).ShouldEqual(12); }
public void decimal_formula() { var formula = new Formula("-5.5*2 + 24 - 0.25*4"); formula.IsValid.ShouldBeTrue(); formula.Evaluate().ShouldEqual(12); }
public void equation_with_two_variables() { var formula = new Formula("a*(5-b)"); formula.IsValid.ShouldBeTrue(); formula.Evaluate(new { a = 10, b = 3 }).ShouldEqual(20); }
public void complex_formula() { var formula = new Formula("-12*3 + (5-3)*6 + 9/(4-1)"); formula.IsValid.ShouldBeTrue(); formula.Evaluate().ShouldEqual(-21); }
public void invalid_formula_not_closed_bracket() { var formula = new Formula("5 + 7 + ( (3*5) + 2"); formula.IsValid.ShouldBeFalse(); Assert.Throws<MathException>(() => formula.Evaluate()); }
public void invalid_formula_empty_bracket() { var formula = new Formula("5 + 7 + () + 3"); formula.IsValid.ShouldBeFalse(); Assert.Throws<MathException>(() => formula.Evaluate()); }
public void operator _order() { var formula = new Formula("5 * 5 + 7 * 3"); formula.IsValid.ShouldBeTrue(); formula.Evaluate().ShouldEqual(46); }
public void simple_addition() { var formula = new Formula("5 + 7"); formula.IsValid.ShouldBeTrue(); formula.Evaluate().ShouldEqual(12); }
public void invalid_formula_two_operators_in_row() { var formula = new Formula("5 + 7 ++ 5"); formula.IsValid.ShouldBeFalse(); Assert.Throws<MathException>(() => formula.Evaluate()); }
public void invalid_formula_two_negations_in_row() { var formula = new Formula("--5 + 7"); formula.IsValid.ShouldBeFalse(); Assert.Throws<MathException>(() => formula.Evaluate()); }
public void invalid_formula_operator_left_at_the_end() { var formula = new Formula("5 + 7 +"); formula.IsValid.ShouldBeFalse(); Assert.Throws<MathException>(() => formula.Evaluate()); }
public void invalid_formula_operator_in_wrong_place() { var formula = new Formula("5 + 7 + (+2 - 3)"); formula.IsValid.ShouldBeFalse(); Assert.Throws<MathException>(() => formula.Evaluate()); }