mirror of
https://github.com/0xJ1M/MathsEngine.git
synced 2026-06-05 02:10:08 +00:00
Updated unit test coverage
This commit is contained in:
@@ -1,65 +0,0 @@
|
|||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using MathEngine.Parser.Parser.Node;
|
using MathEngine.Parser.Tokeniser;
|
||||||
using MathEngine.Parser.Tokeniser;
|
|
||||||
namespace MathEngine.Parser.Parser
|
namespace MathEngine.Parser.Parser
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -179,24 +179,24 @@
|
|||||||
/// <returns>Returns true if the two Tokens are not equal and false otherwise</returns>
|
/// <returns>Returns true if the two Tokens are not equal and false otherwise</returns>
|
||||||
public static bool operator !=(Token X, Token Y)
|
public static bool operator !=(Token X, Token Y)
|
||||||
{
|
{
|
||||||
if (X.TokenValue == Y.TokenValue)
|
if (X.TokenValue != Y.TokenValue)
|
||||||
{
|
{
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (X.TokenType == Y.TokenType)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (X.NumericalType == Y.NumericalType)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (X.Arity == Y.Arity)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (X.TokenType != Y.TokenType)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (X.NumericalType != Y.NumericalType)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (X.Arity != Y.Arity)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a value that indicates whether the given Token is equal to the current Token instance.
|
/// Returns a value that indicates whether the given Token is equal to the current Token instance.
|
||||||
|
|||||||
Reference in New Issue
Block a user