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)
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)
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)
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)
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)
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)
def testAddNodeWithIndex(self): elem = BaseTree.IndexedNode(rules=[BaseTree.EmptyNode], limit=1) second_elem = BaseTree.EmptyNode(0) self.item.AddNode(elem) self.item.AddNode(second_elem, index=2) self.assertEqual(elem.GetChild(2), second_elem)
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))
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))