using MathEngine.Parser.Tokeniser;
namespace EngineTests
{
///
/// Class for testing the Tokeniser
///
[TestClass]
public class TokeniserTests
{
///
/// Test the tokeniser on a basic string
///
[TestMethod]
public void TestTokeniseBasicString()
{
//Arrange
string testString = "1+1";
Token one = new("1", Token.Type.Numeric, Token.NumericType.Decimal, 0);
List expectedValue = new()
{
one,
Token.Plus,
one
};
//Act
List returnedValue = Tokeniser.Tokenise(testString);
//Assert
Assert.IsTrue(expectedValue.SequenceEqual(returnedValue));
}
///
/// Test the tokeniser on a basic string, but with significant ammounts of whitespace
///
[TestMethod]
public void TestTokeniseBasicStringWithWhiteSpace()
{
//Arrange
string testString = " 1 + 1 ";
Token one = new("1", Token.Type.Numeric, Token.NumericType.Decimal, 0);
List expectedValue = new()
{
one,
Token.Plus,
one
};
//Act
List returnedValue = Tokeniser.Tokenise(testString);
//Assert
Assert.IsTrue(expectedValue.SequenceEqual(returnedValue));
}
///
/// Test the tokeniser on a string which contains a number which is not formatted correctly
///
[TestMethod]
public void TestTokeniseStringWithInvalidNumbr()
{
//Arrange
string testString = "1+11.2.5";
//Act and Assert
Assert.ThrowsException(() => Tokeniser.Tokenise(testString));
}
}
}