def test_is_leaf(self): k = KBucket(range_min=0, range_max=32, maxsize=20) tnode = _TreeNode(k) self.assertTrue(tnode.is_leaf()) # Manually attach two new _TreeNode children tnode.lchild = _TreeNode(k) tnode.rchild = _TreeNode(k) self.assertFalse(tnode.is_leaf())
def test_split_invalidNodeID(self): k = KBucket(range_min=0, range_max=16, maxsize=2) tnode = _TreeNode(k) rt = TreeRoutingTable(node_id=122) rt.active_kbuckets.append(tnode.kbucket) # 122 doesnt fit in [0, 16) split_correctly = rt._split(tnode) self.assertFalse(split_correctly)
def test_split_invalidNotSplittable(self): # KBucket is too small to split k = KBucket(range_min=0, range_max=4, maxsize=2) tnode = _TreeNode(k) rt = TreeRoutingTable(node_id=2) rt.active_kbuckets.append(tnode.kbucket) split_correctly = rt._split(tnode) self.assertFalse(split_correctly)
def test_split_invalidNotLeaf(self): k = KBucket(range_min=0, range_max=32, maxsize=2) tnode = _TreeNode(k) rt = TreeRoutingTable(node_id=12) rt.active_kbuckets.append(tnode.kbucket) split_correctly = rt._split(tnode) self.assertTrue(split_correctly) # Treenode has already been split (so it isnt a leaf) split_correctly = rt._split(tnode) self.assertFalse(split_correctly)
def test_split_validNormal(self): k = KBucket(range_min=0, range_max=32, maxsize=2) tnode = _TreeNode(k) tnode.kbucket.offer_node(generate_node(11)) tnode.kbucket.offer_node(generate_node(22)) rt = TreeRoutingTable(node_id=17) rt.active_kbuckets.append(tnode.kbucket) split_correctly = rt._split(tnode) self.assertTrue(split_correctly) self.assertEquals(1, len(tnode.lchild.kbucket.get_nodes())) self.assertEquals(1, len(tnode.rchild.kbucket.get_nodes())) self.assertFalse(tnode.is_leaf())