示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#10
0
 def testFindFirstNode(self):
     elem = BaseTree.Node()
     self.item.AddNode(elem)
     self.assertEqual(self.item.FindNode(type(elem), 1), elem)
示例#11
0
 def testAddNode(self):
     elem = BaseTree.Node()
     self.item.AddNode(elem)
     self.assertEqual(elem, self.item.root)
示例#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))
示例#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))
示例#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)
示例#15
0
 def testAddInvalidNode(self):
     elem = BaseTree.Node()
     self.item.AddNode(elem)
     self.assertRaises(BaseTree.CannotAddToTreeException, self.item.AddNode,
                       BaseTree.Node())