Upsilon/UpsilonTests/BasicMathExpressions.cs

59 lines
1.8 KiB
C#
Raw Normal View History

using Upsilon.BaseTypes.Number;
2018-11-10 12:11:36 +00:00
using Upsilon.Evaluator;
using Upsilon.Parser;
using Xunit;
namespace UpsilonTests
{
public class BasicMathExpressions
{
[Theory]
[InlineData("1+1", 2)]
[InlineData("1000+1", 1001)]
[InlineData("1+1000", 1001)]
[InlineData("1 + 1000", 1001)]
[InlineData("8612648+6153205", 14765853)]
[InlineData("0.5 + 2", 2.5)]
[InlineData("0.005 + 2.2", 2.205)]
public void Addition(string input, double expectedOutput)
{
var actual = new Script(input).Evaluate<Number>();
Assert.Equal(expectedOutput, (double)actual, 8);
2018-11-10 12:11:36 +00:00
}
[Theory]
[InlineData("1-1", 0)]
[InlineData("100-45", 55)]
[InlineData("1-1200", -1199)]
[InlineData("341564-5646843", -5305279)]
[InlineData("1-0.5", 0.5)]
[InlineData("10.256-2.8546", 7.4014)]
public void Subtraction(string input, double expectedOutput)
{
var actual = new Script(input).Evaluate<Number>();
Assert.Equal(expectedOutput, (double)actual, 8);
2018-11-10 12:11:36 +00:00
}
[Theory]
[InlineData("1*1", 1)]
[InlineData("100 * 100", 10000)]
[InlineData("21312 * 41684", 888369408)]
public void Multiplication(string input, double expectedOutput)
{
var actual = new Script(input).Evaluate<Number>();
Assert.Equal(expectedOutput, (double)actual, 8);
2018-11-10 12:11:36 +00:00
}
[Theory]
[InlineData("1/1", 1)]
[InlineData("1000 / 10", 100)]
[InlineData("656486 / 5146", 127)]
[InlineData("656486 / 5146.0", 127.57209483)]
2018-11-10 12:11:36 +00:00
public void Divison(string input, double expectedOutput)
{
var actual = new Script(input).Evaluate<Number>();
Assert.Equal(expectedOutput, (double)actual, 8);
2018-11-10 12:11:36 +00:00
}
}
}