2018-11-14 12:09:01 +00:00
|
|
|
using Upsilon.BaseTypes.Number;
|
2018-11-10 12:11:36 +00:00
|
|
|
using Upsilon.Evaluator;
|
|
|
|
using Upsilon.Parser;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace UpsilonTests
|
|
|
|
{
|
|
|
|
public class MathPrecedence
|
|
|
|
{
|
|
|
|
[Theory]
|
|
|
|
[InlineData("5 * (10 + 5)", 75)]
|
|
|
|
[InlineData("(10 + 5) * 5", 75)]
|
|
|
|
public void Parenthesis(string input, double expectedOutput)
|
|
|
|
{
|
2018-11-17 11:40:28 +00:00
|
|
|
var actual = new Script(input).Evaluate<long>();
|
2018-11-10 12:11:36 +00:00
|
|
|
Assert.Equal(expectedOutput, actual, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
[InlineData("5 * 10 + 5", 55)]
|
|
|
|
[InlineData("5 + 10 * 5", 55)]
|
|
|
|
public void MultiplicationBeforeAddition(string input, double expectedOutput)
|
|
|
|
{
|
2018-11-17 11:40:28 +00:00
|
|
|
var actual = new Script(input).Evaluate<long>();
|
2018-11-10 12:11:36 +00:00
|
|
|
Assert.Equal(expectedOutput, actual, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|