Updated unit test coverage

This commit is contained in:
Jim
2023-09-07 22:56:36 +01:00
parent 0225ae1f84
commit 5be2ea6e23
3 changed files with 10 additions and 76 deletions

View File

@@ -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));
}
}
}

View File

@@ -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>

View File

@@ -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.