public void OptimiseTokensToIncreaseExponent() { TokensOptimiserNondestructive to = new TokensOptimiserNondestructive(); //var input = new List<Token>() { _one, CopyToken(_one), _multiply, CopyToken(_one), CopyToken(_multiply), CopyToken(_one), CopyToken(_multiply) }; var input = new List <Token>() { _one, _one, _multiply, _one, _multiply, _one, _multiply }; var expectedOutput = new List <Token>() { _one, _four, _exponent }; to.InjectTokens(CopyTokens(input)); to.OptimiseTokensNondestructive(); var actualOutput = to.OptimisedTokens; var e = $"Expected Output:\n{TokensToString(expectedOutput)}\nActual Output:\n{TokensToString(actualOutput)}"; for (int i = 0; i < expectedOutput.Count; i++) { Assert.True(expectedOutput[i].Value == actualOutput[i].Value, e); Assert.True(expectedOutput[i].Type == actualOutput[i].Type, e); } }
public void OptimiseTokensResolveToZero() { TokensOptimiserNondestructive to = new TokensOptimiserNondestructive(); //var input = new List<Token>() { _one, CopyToken(_one), _multiply, CopyToken(_one), CopyToken(_multiply), CopyToken(_one), CopyToken(_multiply) }; var input = new List <Token>() { _one, _sin, _one, _varX, _divide, _zero, _multiply, _plus }; var expectedOutput = new List <Token>() { _one, _sin, _zero, _plus }; to.InjectTokens(CopyTokens(input)); to.OptimiseTokensNondestructive(); var actualOutput = to.OptimisedTokens; var e = $"Expected Output:\n{TokensToString(expectedOutput)}\nActual Output:\n{TokensToString(actualOutput)}"; for (int i = 0; i < expectedOutput.Count; i++) { Assert.True(expectedOutput[i].Value == actualOutput[i].Value, e); Assert.True(expectedOutput[i].Type == actualOutput[i].Type, e); } }