Initial commit
This commit is contained in:
commit
4b1294b32d
23 changed files with 5134 additions and 0 deletions
63
MathInterpreter.Test/MathExpressionTests.cs
Normal file
63
MathInterpreter.Test/MathExpressionTests.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
using MathInterpreter.Core;
|
||||
|
||||
namespace MathInterpreter.Test;
|
||||
|
||||
public sealed class MathExpressionTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("123 + 45")]
|
||||
[InlineData("123+ 45")]
|
||||
[InlineData("41 - 12")]
|
||||
[InlineData("41 -12")]
|
||||
[InlineData("12 * 0.9")]
|
||||
[InlineData("12*0.9")]
|
||||
[InlineData("2.32 / -3.9198")]
|
||||
public void MathExpression_Construction_Valid(string expression)
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var _ = new MathExpression(expression);
|
||||
};
|
||||
|
||||
action.Should().NotThrow("Valid expression passed, don't expect any exceptions");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("123 + ", "Right operand is missing")]
|
||||
[InlineData("+ 456", "Operator is missing")]
|
||||
[InlineData("123 / 0", "Division by zero is not allowed")]
|
||||
[InlineData("123 abc 456", "Unknown operator: a")]
|
||||
public void MathExpression_Construction_Invalid(string expression, string expectedExceptionMessage)
|
||||
{
|
||||
var action = () =>
|
||||
{
|
||||
var _ = new MathExpression(expression);
|
||||
};
|
||||
|
||||
action.Should().Throw<ExpressionException>().WithMessage(expectedExceptionMessage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("2 + 2", 4.0)]
|
||||
[InlineData("10 - -3", 13.0)]
|
||||
[InlineData("5.2 * 2", 10.4)]
|
||||
[InlineData("-8 / 2", -4.0)]
|
||||
public void Result_Valid(string expression, double expectedResult)
|
||||
{
|
||||
var mathExpression = new MathExpression(expression);
|
||||
|
||||
mathExpression.Result.Should().Be(expectedResult);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("2 + 2aa", "2 + 2")]
|
||||
[InlineData("10 - 3", "10 - 3")]
|
||||
[InlineData("5 * 2f", "5 * 2")]
|
||||
[InlineData(" 8 / 2", "8 / 2")]
|
||||
public void StringRepresentation(string expression, string expectedString)
|
||||
{
|
||||
var mathExpression = new MathExpression(expression);
|
||||
|
||||
mathExpression.ToString().Should().Be(expectedString);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue