private void ShowTokens() { Tokenizer tokenizer = new Tokenizer(tbSource.Text, new[] {'+', '-', '*', '/', '^', '(', ')'}); Token currentToken = tokenizer.ReadNextToken(); tbTokenOutput.Text = string.Empty; tbPostfix.Text = string.Empty; tbResult.Text = string.Empty; while (currentToken.Type != TokenType.None) { tbTokenOutput.AppendText(string.Format("Type: {0} - Value: '{1}'{2}", currentToken.GetTypeAsString(), currentToken.GetValueAsString(), Environment.NewLine)); currentToken = tokenizer.ReadNextToken(); } }
public void TokenizingTest_ReadAllTokens() { // Arrange int index = 0; string[] expectedTokens = { "10", "-", "2", "+", "3232", "*", "4", "/", "5.2", "(", ")" }; string source = string.Join(string.Empty, expectedTokens); // = "10-2+3232*4/5.2()" ITokenizer tokenizer = new Tokenizer().Initialize(source, new[] { '+', '-', '*', '/', '^', '(', ')' }); // Act and assert each act. Token[] allTokens = tokenizer.ReadAllTokens(); foreach (var token in allTokens) { Assert.AreEqual(expectedTokens[index++], token.GetValueAsString()); } // Assert end result. Assert.AreEqual(expectedTokens.Length, index); }
public void TokenizingTest_ReadNextToken() { // Arrange int count = 0; string[] expectedTokens = {"10", "-", "2", "+", "3232", "*", "4", "/", "5.2", "(", ")"}; string source = string.Join(string.Empty, expectedTokens); // = "10-2+3232*4/5.2()" ITokenizer tokenizer = new Tokenizer(source, new[] { '+', '-', '*', '/', '^', '(', ')' }); // Act and assert each act. Token currentToken = tokenizer.ReadNextToken(); while (currentToken.Type != TokenType.None) { Assert.AreEqual(expectedTokens[count], currentToken.GetValueAsString()); currentToken = tokenizer.ReadNextToken(); ++count; } // Assert end result. Assert.AreEqual(expectedTokens.Length, count); }