Upsilon/UpsilonTests/GeneralTests/BasicMathExpressions.cs

63 lines
2.0 KiB
C#
Raw Normal View History

2018-11-19 16:22:25 +00:00
using System;
using System.Diagnostics;
2018-11-10 12:11:36 +00:00
using Upsilon.Evaluator;
using Xunit;
namespace UpsilonTests
{
2018-11-23 11:55:28 +00:00
public class BasicMathExpressions : TestClass
2018-11-10 12:11:36 +00:00
{
2018-11-23 11:55:28 +00:00
public BasicMathExpressions(StaticScriptFixture fix) : base(fix)
{
}
2018-11-10 12:11:36 +00:00
[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)
{
2018-11-23 11:55:28 +00:00
var actual = new Script(input, BoundScope, StaticScope).Evaluate<double>();
Assert.Equal(expectedOutput, 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)
{
2018-11-23 11:55:28 +00:00
var actual = new Script(input, BoundScope, StaticScope).Evaluate<double>();
Assert.Equal(expectedOutput, 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)
{
2018-11-23 11:55:28 +00:00
var actual = new Script(input, BoundScope, StaticScope).Evaluate<double>();
Assert.Equal(expectedOutput, 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)
{
2018-11-23 11:55:28 +00:00
var actual = new Script(input, BoundScope, StaticScope).Evaluate<double>();
Assert.Equal(expectedOutput, actual, 8);
2018-11-10 12:11:36 +00:00
}
}
}