def test_bucket_index_multiple_buckets(self): """ Ensures the expected index is returned when multiple buckets exist. """ parent_node_id = 'deadbeef' r = RoutingTable(parent_node_id) r._split_bucket(0) split_point = int((2 ** 512) / 2) lower_key = hex(split_point - 1)[2:] higher_key = hex(split_point + 1)[2:] expected_lower_index = 0 expected_higher_index = 1 actual_lower_index = r._bucket_index(lower_key) actual_higher_index = r._bucket_index(higher_key) self.assertEqual(expected_lower_index, actual_lower_index) self.assertEqual(expected_higher_index, actual_higher_index)
def test_bucket_index_as_string_and_int(self): """ Ensures that the specified key can be expressed as both a string and integer value. """ parent_node_id = 'deadbeef' r = RoutingTable(parent_node_id) # key as a string test_key = 'abc123' expected_index = 0 actual_index = r._bucket_index(test_key) self.assertEqual(expected_index, actual_index) # key as an integer test_key = '1234567' actual_index = r._bucket_index(test_key) self.assertEqual(expected_index, actual_index)
def test_bucket_index_single_bucket(self): """ Ensures the expected index is returned when only a single bucket exists. """ parent_node_id = 'deadbeef' r = RoutingTable(parent_node_id) # a simple test with only one bucket in the routing table. test_key = 'abc123' expected_index = 0 actual_index = r._bucket_index(test_key) self.assertEqual(expected_index, actual_index)