mirror of
https://github.com/0xJ1M/MathsEngine.git
synced 2026-06-05 01:00:06 +00:00
65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using MathEngine.Parser.Tokeniser;
|
|
|
|
namespace EngineTests
|
|
{
|
|
/// <summary>
|
|
/// Class for testing the Tokeniser
|
|
/// </summary>
|
|
[TestClass]
|
|
public class TokeniserTests
|
|
{
|
|
/// <summary>
|
|
/// Test the tokeniser on a basic string
|
|
/// </summary>
|
|
[TestMethod]
|
|
public void TestTokeniseBasicString()
|
|
{
|
|
//Arrange
|
|
string testString = "1+1";
|
|
Token one = new("1", Token.Type.Numeric, Token.NumericType.Decimal, 0);
|
|
List<Token> expectedValue = new()
|
|
{
|
|
one,
|
|
Token.Plus,
|
|
one
|
|
};
|
|
//Act
|
|
List<Token> returnedValue = Tokeniser.Tokenise(testString);
|
|
//Assert
|
|
Assert.IsTrue(expectedValue.SequenceEqual(returnedValue));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test the tokeniser on a basic string, but with significant ammounts of whitespace
|
|
/// </summary>
|
|
[TestMethod]
|
|
public void TestTokeniseBasicStringWithWhiteSpace()
|
|
{
|
|
//Arrange
|
|
string testString = " 1 + 1 ";
|
|
Token one = new("1", Token.Type.Numeric, Token.NumericType.Decimal, 0);
|
|
List<Token> expectedValue = new()
|
|
{
|
|
one,
|
|
Token.Plus,
|
|
one
|
|
};
|
|
//Act
|
|
List<Token> returnedValue = Tokeniser.Tokenise(testString);
|
|
//Assert
|
|
Assert.IsTrue(expectedValue.SequenceEqual(returnedValue));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test the tokeniser on a string which contains a number which is not formatted correctly
|
|
/// </summary>
|
|
[TestMethod]
|
|
public void TestTokeniseStringWithInvalidNumbr()
|
|
{
|
|
//Arrange
|
|
string testString = "1+11.2.5";
|
|
//Act and Assert
|
|
Assert.ThrowsException<Exception>(() => Tokeniser.Tokenise(testString));
|
|
}
|
|
}
|
|
} |