initial commit
This commit is contained in:
57
UpsilonTests/BasicMathExpressions.cs
Normal file
57
UpsilonTests/BasicMathExpressions.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
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 = (double)Parser.Parse(input).Evaluate();
|
||||
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 = (double)Parser.Parse(input).Evaluate();
|
||||
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 = (double)Parser.Parse(input).Evaluate();
|
||||
Assert.Equal(expectedOutput, actual, 8);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("1/1", 1)]
|
||||
[InlineData("1000 / 10", 100)]
|
||||
[InlineData("656486 / 5146", 127.57209483)]
|
||||
public void Divison(string input, double expectedOutput)
|
||||
{
|
||||
var actual = (double)Parser.Parse(input).Evaluate();
|
||||
Assert.Equal(expectedOutput, actual, 8);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
28
UpsilonTests/MathPrecedence.cs
Normal file
28
UpsilonTests/MathPrecedence.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
19
UpsilonTests/UpsilonTests.csproj
Normal file
19
UpsilonTests/UpsilonTests.csproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Upsilon\Upsilon.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user