28 lines
758 B
C#
28 lines
758 B
C#
|
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)
|
||
|
{
|
||
|
var actual = (double)Parser.Parse(input).Evaluate();
|
||
|
Assert.Equal(expectedOutput, actual, 8);
|
||
|
}
|
||
|
|
||
|
[Theory]
|
||
|
[InlineData("5 * 10 + 5", 55)]
|
||
|
[InlineData("5 + 10 * 5", 55)]
|
||
|
public void MultiplicationBeforeAddition(string input, double expectedOutput)
|
||
|
{
|
||
|
var actual = (double)Parser.Parse(input).Evaluate();
|
||
|
Assert.Equal(expectedOutput, actual, 8);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|