Beispiel #1
0
    def test_remove_node(self):
        k = 3
        bucket = KBucket(0, 10, k)
        nodes = [mknode() for _ in range(10)]
        for node in nodes:
            bucket.add_node(node)

        replacement_nodes = bucket.replacement_nodes
        self.assertEqual(list(bucket.nodes.values()), nodes[:k])
        self.assertEqual(list(replacement_nodes.values()), nodes[k:])

        bucket.remove_node(nodes.pop())
        self.assertEqual(list(bucket.nodes.values()), nodes[:k])
        self.assertEqual(list(replacement_nodes.values()), nodes[k:])

        bucket.remove_node(nodes.pop(0))
        self.assertEqual(list(bucket.nodes.values()),
                         nodes[:k - 1] + nodes[-1:])
        self.assertEqual(list(replacement_nodes.values()), nodes[k - 1:-1])

        shuffle(nodes)
        for node in nodes:
            bucket.remove_node(node)
        self.assertEqual(len(bucket), 0)
        self.assertEqual(len(replacement_nodes), 0)
Beispiel #2
0
    def test_remove_node(self):
        k = 3
        bucket = KBucket(0, 10, k)
        nodes = [mknode() for _ in range(10)]
        for node in nodes:
            bucket.add_node(node)

        replacement_nodes = bucket.replacement_nodes
        self.assertEqual(list(bucket.nodes.values()), nodes[:k])
        self.assertEqual(list(replacement_nodes.values()), nodes[k:])

        bucket.remove_node(nodes.pop())
        self.assertEqual(list(bucket.nodes.values()), nodes[:k])
        self.assertEqual(list(replacement_nodes.values()), nodes[k:])

        bucket.remove_node(nodes.pop(0))
        self.assertEqual(list(bucket.nodes.values()), nodes[:k-1] + nodes[-1:])
        self.assertEqual(list(replacement_nodes.values()), nodes[k-1:-1])

        shuffle(nodes)
        for node in nodes:
            bucket.remove_node(node)
        self.assertEqual(len(bucket), 0)
        self.assertEqual(len(replacement_nodes), 0)
Beispiel #3
0
    def test_remove_node(self, mknode):  # pylint: disable=no-self-use
        k = 3
        bucket = KBucket(0, 10, k)
        nodes = [mknode() for _ in range(10)]
        for node in nodes:
            bucket.add_node(node)

        replacement_nodes = bucket.replacement_nodes
        assert list(bucket.nodes.values()) == nodes[:k]
        assert list(replacement_nodes.values()) == nodes[k:]

        bucket.remove_node(nodes.pop())
        assert list(bucket.nodes.values()) == nodes[:k]
        assert list(replacement_nodes.values()) == nodes[k:]

        bucket.remove_node(nodes.pop(0))
        assert list(bucket.nodes.values()) == nodes[:k - 1] + nodes[-1:]
        assert list(replacement_nodes.values()) == nodes[k - 1:-1]

        shuffle(nodes)
        for node in nodes:
            bucket.remove_node(node)
        assert not bucket
        assert not replacement_nodes