Esempio n. 1
0
        public void TestCountNodes()
        {
            Node no1 = new Node(new WordToken("1"));
            Node no2 = new Node(new WordToken("2"));
            Node no3 = new Node(new WordToken("3"));
            Node no4 = new Node(new WordToken("4"));
            Node no5 = new Node(new WordToken("5"));
            Node no6 = new Node(new WordToken("6"));

            binaryTree.insertNode(no1, no2);
            binaryTree.insertNode(binaryTree.root, no3);
            binaryTree.insertNode(binaryTree.root, no4);
            binaryTree.insertNode(binaryTree.root, no5);
            binaryTree.insertNode(binaryTree.root, no6);

            List <Token> tokenList = new List <Token>();

            binaryTree.convertTreeToList(binaryTree.root, ref tokenList);
            Assert.AreEqual(tokenList.Count, binaryTree.count);
            Assert.AreNotEqual(tokenList.Count + 1, binaryTree.count);

            binaryTree = null;
            Assert.IsNull(binaryTree);

            binaryTree = new BinaryTreeImp();
            Assert.AreEqual(0, binaryTree.count);
        }
Esempio n. 2
0
 private void _term()
 {
     if (next.GetType() == typeof(ParenthesisBeginToken) && (!_tokens.isEmpty()))
     {
         Token token = _tokens.getNextToken();
         BinaryTree = new BinaryTreeImp(); //reset the binary tree to ready for a new branch build
         next       = _tokens.PeekToken();
         _term();
     }
     if (next.GetType() == typeof(ParenthesisEndToken) && (!_tokens.isEmpty()))
     {
         Token token = _tokens.getNextToken();
         _buildTreeFromAllRemainingBranches();
         if (_tokens.isEmpty())
         {
             return;
         }
         next = _tokens.PeekToken();
         _term();
     }
     if (next.GetType() == typeof(WordToken) && (!_tokens.isEmpty()))
     {
         Token wordToken = _tokens.getNextToken();
         branchesStack.Push(new Node(wordToken));
         next = _tokens.PeekToken();
         _term();
     }
     if (_tokens.isEmpty())
     {
         return;
     }
 }
Esempio n. 3
0
        public void TestCountNodes()
        {
            Node no1 = new Node(new WordToken("1"));
            Node no2 = new Node(new WordToken("2"));
            Node no3 = new Node(new WordToken("3"));
            Node no4 = new Node(new WordToken("4"));
            Node no5 = new Node(new WordToken("5"));
            Node no6 = new Node(new WordToken("6"));
            binaryTree.insertNode(no1, no2);
            binaryTree.insertNode(binaryTree.root, no3);
            binaryTree.insertNode(binaryTree.root, no4);
            binaryTree.insertNode(binaryTree.root, no5);
            binaryTree.insertNode(binaryTree.root, no6);

            List<Token> tokenList = new List<Token>();
            binaryTree.convertTreeToList(binaryTree.root, ref tokenList);
            Assert.AreEqual(tokenList.Count, binaryTree.count);
            Assert.AreNotEqual(tokenList.Count+1, binaryTree.count);

            binaryTree = null;
            Assert.IsNull(binaryTree);

            binaryTree = new BinaryTreeImp();
            Assert.AreEqual(0, binaryTree.count);
        }
Esempio n. 4
0
        public Parser(Tokens tokens)
        {
            branchesStack = new Stack<Node>();
            BinaryTree = new BinaryTreeImp();
            _tokens = tokens;

            next = _tokens.PeekToken();
            if (next.ToString() == "(")
                _query();
            else //NOTE: if the first token is not a parenthesis then all tokens are treated as word tokens, not logic tokens or others
                _buildTreeWordsOnly();
        }
Esempio n. 5
0
        public Parser(Tokens tokens)
        {
            branchesStack = new Stack <Node>();
            BinaryTree    = new BinaryTreeImp();
            _tokens       = tokens;

            next = _tokens.PeekToken();
            if (next.ToString() == "(")
            {
                _query();
            }
            else //NOTE: if the first token is not a parenthesis then all tokens are treated as word tokens, not logic tokens or others
            {
                _buildTreeWordsOnly();
            }
        }
Esempio n. 6
0
 public void Init()
 {
     binaryTree = new BinaryTreeImp();
 }
Esempio n. 7
0
 private void newSimpleTree(Node root, Node leaf)
 {
     BinaryTree = new BinaryTreeImp();
     BinaryTree.insertNode(root, leaf);
     branchesStack.Push(BinaryTree.root);
 }
Esempio n. 8
0
 private void newSimpleTree(Node root, Node leaf)
 {
     BinaryTree = new BinaryTreeImp();
     BinaryTree.insertNode(root, leaf);
     branchesStack.Push(BinaryTree.root);
 }
Esempio n. 9
0
 private void _term()
 {
     if (next.GetType() == typeof(ParenthesisBeginToken) && (!_tokens.isEmpty()))
     {
         Token token = _tokens.getNextToken();
         BinaryTree = new BinaryTreeImp(); //reset the binary tree to ready for a new branch build
         next = _tokens.PeekToken();
         _term();
     }
     if (next.GetType() == typeof(ParenthesisEndToken) && (!_tokens.isEmpty()))
     {
         Token token = _tokens.getNextToken();
         _buildTreeFromAllRemainingBranches();
         if (_tokens.isEmpty())
             return;
         next = _tokens.PeekToken();
         _term();
     }
     if (next.GetType() == typeof(WordToken) && (!_tokens.isEmpty()))
     {
         Token wordToken = _tokens.getNextToken();
         branchesStack.Push(new Node(wordToken));
         next = _tokens.PeekToken();
         _term();
     }
     if (_tokens.isEmpty())
         return;
 }
Esempio n. 10
0
 public void Init()
 {
     binaryTree = new BinaryTreeImp();
 }