Beispiel #1
0
 def testFindSecondNode(self):
     elem = BaseTree.Node(rules=[BaseTree.Node])
     self.item.AddNode(elem)
     second = BaseTree.Node()
     self.item.AddNode(second)
     node = self.item.FindNode(type(elem), 2)
     self.assertEqual(node, second)
Beispiel #2
0
 def testFindNodeWithStringIndexOnSecondLevel(self):
     elem = BaseTree.Node(rules=[BaseTree.IndexedNode])
     self.item.AddNode(elem)
     second = BaseTree.IndexedNode(rules=[BaseTree.Node])
     self.item.AddNode(second)
     third = BaseTree.Node()
     self.item.AddNode(third, "S")
     self.assertEqual(self.item.FindNodeByIndex("S"), third)
Beispiel #3
0
 def testFailure(self):
     elem = BaseTree.Node(rules=[BaseTree.Node])
     self.item.AddNode(elem)
     second = BaseTree.Node()
     self.item.AddNode(second)
     third = BaseTree.Node(rules=[BaseTree.EmptyNode])
     self.item.AddNode(third)
     with self.assertRaises(BaseTree.CannotFindInTreeException):
         self.item.FindNode(BaseTree.EmptyNode, 1)
Beispiel #4
0
 def testFindFirstEmptyNodeOnFirstChild(self):
     elem = BaseTree.Node(rules=[BaseTree.Node])
     self.item.AddNode(elem)
     second = BaseTree.Node(rules=[BaseTree.EmptyNode])
     self.item.AddNode(second)
     third = BaseTree.EmptyNode(0)
     self.item.AddNode(third)
     node = self.item.FindNode(BaseTree.EmptyNode, 1)
     self.assertEqual(node, third)
Beispiel #5
0
 def testAddNodeToSecondNode(self):
     elem = BaseTree.Node(rules=[BaseTree.EmptyNode])
     self.item.AddNode(elem)
     second = BaseTree.EmptyNode(0)
     self.item.AddNode(second)
     third = BaseTree.EmptyNode(0, rules=[BaseTree.Node])
     self.item.AddNode(third)
     fourth = BaseTree.Node()
     self.item.AddNode(fourth)
     self.assertEqual(third.GetChild(0), fourth)
Beispiel #6
0
 def testAddNodeAddsToNextLevelWithExpandedLimit(self):
     # this test confirms the above still happens when the limit is 2
     elem = BaseTree.Node(rules=[BaseTree.EmptyNode, BaseTree.IndexedNode],
                          limit=2)
     next = BaseTree.EmptyNode(0, rules=[BaseTree.Node])
     third = BaseTree.Node()
     self.item.AddNode(elem)
     self.item.AddNode(next)
     self.item.AddNode(third)
     self.assertEqual(next.GetChild(0), third)
Beispiel #7
0
 def testAddNodeAddsToCurrentLevelWithRelevantRuleAndLimit(self):
     # this test confirms the first spot for third to land in is a second child of elem, because elem lets you have
     # node as a child and can have 2 children.
     elem = BaseTree.Node(rules=[BaseTree.EmptyNode, BaseTree.Node],
                          limit=2)
     next = BaseTree.EmptyNode(0, rules=[BaseTree.Node])
     third = BaseTree.Node()
     self.item.AddNode(elem)
     self.item.AddNode(next)
     self.item.AddNode(third)
     self.assertEqual(elem.GetChild(1), third)
Beispiel #8
0
 def testAddNodeAddsToNextLevel(self):
     # this test confirms that with a parent who allows 1 child which has to be empty or indexed, Next is it's child
     # and third is a child of next.
     elem = BaseTree.Node(rules=[BaseTree.EmptyNode, BaseTree.IndexedNode],
                          limit=1)
     next = BaseTree.EmptyNode(0, rules=[BaseTree.Node])
     third = BaseTree.Node()
     self.item.AddNode(elem)
     self.item.AddNode(next)
     self.item.AddNode(third)
     self.assertEqual(next.GetChild(0), third)
Beispiel #9
0
 def testFindEmptyNodeOnSecondChild(self):
     elem = BaseTree.Node(rules=[BaseTree.Node])
     self.item.AddNode(elem)
     second = BaseTree.Node()
     self.item.AddNode(second)
     third = BaseTree.Node(rules=[BaseTree.EmptyNode])
     self.item.AddNode(third)
     fourth = BaseTree.EmptyNode(0)
     self.item.AddNode(fourth)
     node = self.item.FindNode(BaseTree.EmptyNode, 1)
     self.assertEqual(node, fourth)
Beispiel #10
0
 def testFindFirstNode(self):
     elem = BaseTree.Node()
     self.item.AddNode(elem)
     self.assertEqual(self.item.FindNode(type(elem), 1), elem)
Beispiel #11
0
 def testAddNode(self):
     elem = BaseTree.Node()
     self.item.AddNode(elem)
     self.assertEqual(elem, self.item.root)
Beispiel #12
0
 def testAddNodeOverLimit(self):
     elem = BaseTree.Node(rules=[BaseTree.EmptyNode, BaseTree.IndexedNode],
                          limit=-1)
     self.item.AddNode(elem)
     self.assertRaises(BaseTree.CannotAddToTreeException, self.item.AddNode,
                       BaseTree.EmptyNode(0))
Beispiel #13
0
 def testAddTwoValidNodes(self):
     elem = BaseTree.Node(rules=[BaseTree.EmptyNode, BaseTree.IndexedNode])
     self.item.AddNode(elem)
     self.item.AddNode(BaseTree.EmptyNode(0))
     self.assertEqual(1, len(elem.children))
Beispiel #14
0
 def testFindNodeWithStringIndex(self):
     elem = BaseTree.IndexedNode(rules=[BaseTree.Node])
     self.item.AddNode(elem)
     second = BaseTree.Node()
     self.item.AddNode(second, "P1")
     self.assertEqual(self.item.FindNodeByIndex("P1"), second)
Beispiel #15
0
 def testAddInvalidNode(self):
     elem = BaseTree.Node()
     self.item.AddNode(elem)
     self.assertRaises(BaseTree.CannotAddToTreeException, self.item.AddNode,
                       BaseTree.Node())