Upsilon/UpsilonTests/GeneralTests/BasicMathExpressions.cs

63 lines
2.0 KiB
C#

using System;
using System.Diagnostics;
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
{
public class BasicMathExpressions : TestClass
{
public BasicMathExpressions(StaticScriptFixture fix) : base(fix)
{
}
[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, BoundScope, StaticScope).Evaluate<double>();
Assert.Equal(expectedOutput, actual, 8);
}
[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, BoundScope, StaticScope).Evaluate<double>();
Assert.Equal(expectedOutput, actual, 8);
}
[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, BoundScope, StaticScope).Evaluate<double>();
Assert.Equal(expectedOutput, actual, 8);
}
[Theory]
[InlineData("1/1", 1)]
[InlineData("1000 / 10", 100)]
[InlineData("656486 / 5146", 127)]
[InlineData("656486 / 5146.0", 127.57209483)]
public void Divison(string input, double expectedOutput)
{
var actual = new Script(input, BoundScope, StaticScope).Evaluate<double>();
Assert.Equal(expectedOutput, actual, 8);
}
}
}