예제 #1
0
 def test_kbucket_index_multiple_buckets(self):
     """
     Ensures the expected index is returned when multiple buckets exist.
     """
     parent_node_id = 'abc'
     r = RoutingTable(parent_node_id)
     r._split_bucket(0)
     split_point = (2 ** 512) / 2
     lower_key = split_point - 1
     higher_key = split_point + 1
     expected_lower_index = 0
     expected_higher_index = 1
     actual_lower_index = r._kbucket_index(lower_key)
     actual_higher_index = r._kbucket_index(higher_key)
     self.assertEqual(expected_lower_index, actual_lower_index)
     self.assertEqual(expected_higher_index, actual_higher_index)
예제 #2
0
 def test_kbucket_index_as_string_and_int(self):
     """
     Ensures that the specified key can be expressed as both a string
     and integer value.
     """
     parent_node_id = 'abc'
     r = RoutingTable(parent_node_id)
     # key as a string
     test_key = 'abc123'
     expected_index = 0
     actual_index = r._kbucket_index(test_key)
     self.assertEqual(expected_index, actual_index)
     # key as an integer
     test_key = 1234567
     actual_index = r._kbucket_index(test_key)
     self.assertEqual(expected_index, actual_index)
예제 #3
0
 def test_kbucket_index_single_bucket(self):
     """
     Ensures the expected index is returned when only a single bucket
     exists.
     """
     parent_node_id = 'abc'
     r = RoutingTable(parent_node_id)
     # a simple test with only one kbucket in the routing table.
     test_key = 'abc123'
     expected_index = 0
     actual_index = r._kbucket_index(test_key)
     self.assertEqual(expected_index, actual_index)