def test_index(): from openre.helpers import OrderedDict data = OrderedDict([ (1, OrderedDict([(100, 200), (120, 220)])), (2, OrderedDict([(111, 211)])), (3, OrderedDict([(122, 222), (126, 213), (126, 213)])), ]) index = ReceiverIndex( data ) for vector in [index.local_address, index.is_spiked, index.remote_domain, index.remote_address]: assert len(vector) == 5 assert index.pos == 4 assert list(index.local_address.data) == [200, 220, 211, 222, 213] assert list(index.is_spiked.data) == [0, 0, 0, 0, 0] assert list(index.remote_domain.data) == [1, 1, 2, 3, 3] assert list(index.remote_address.data) == [100, 120, 111, 122, 126] assert index.address_to_index[200] == 0 assert index.address_to_index[222] == 3 assert index.get_local_address(2, 111) == 211 assert index.get_local_address(2, 122) is None # check add method index2 = ReceiverIndex() for domain_index in data.keys(): for remote_address in data[domain_index].keys(): local_address = data[domain_index][remote_address] index2.add(local_address, domain_index, remote_address) # additional call should be ignored index2.add(local_address, domain_index, remote_address) index2.shrink() assert list(index.local_address.data) == list(index2.local_address.data) assert list(index.is_spiked.data) == list(index2.is_spiked.data) assert list(index.remote_domain.data) == list(index2.remote_domain.data) assert list(index.remote_address.data) == list(index2.remote_address.data) # check rebuild data = OrderedDict([ (77, OrderedDict([(5, 12), (6, 13)])), (218, OrderedDict([(1, 10), (12, 20)])), ]) index2.rebuild(data) assert index2.pos == 3 assert len(index2.local_address.data) == 4
def test_index(): from openre.helpers import OrderedDict data = OrderedDict([ (218, OrderedDict([(1, (10, 41)), (12, (20, 42))])), (300, OrderedDict([(1, (12, 43))])), (77, OrderedDict([(5, (12, 44)), (6, (13, 45))])), ]) index = TransmitterIndex( data ) for vector in [index.local_address, index.is_spiked, index.key]: assert len(vector) == 3 for vector in [index.value, index.remote_domain, index.remote_address, index.remote_receiver_index]: assert len(vector) == 5 assert index.key_pos == 2 assert index.value_pos == 4 assert list(index.local_address.data) == [218, 300, 77] assert list(index.is_spiked.data) == [0, 0, 0] assert list(index.key.data) == [1, 2, 4] assert list(index.value.data) == [null, 0, null, null, 3] assert list(index.remote_domain.data) == [1, 12, 1, 5, 6] assert list(index.remote_address.data) == [10, 20, 12, 12, 13] assert list(index.remote_receiver_index.data) == [41, 42, 43, 44, 45] assert index.address_to_key_index[218] == 0 assert index.address_to_key_index[77] == 2 # check add method index2 = TransmitterIndex() for local_address in data.keys(): for domain_index in data[local_address].keys(): remote_address, remote_receiver_index \ = data[local_address][domain_index] index2.add(local_address, domain_index, remote_address, remote_receiver_index) # additional call should be ignored index2.add(local_address, domain_index, remote_address, remote_receiver_index) index2.shrink() assert list(index.local_address.data) == list(index2.local_address.data) assert list(index.is_spiked.data) == list(index2.is_spiked.data) assert list(index.key.data) == list(index2.key.data) assert list(index.value.data) == list(index2.value.data) assert list(index.remote_domain.data) == list(index2.remote_domain.data) assert list(index.remote_address.data) == list(index2.remote_address.data) assert list(index.remote_receiver_index.data) \ == list(index2.remote_receiver_index.data) # check rebuild data = OrderedDict([ (77, OrderedDict([(5, (12, 44)), (6, (13, 45))])), (218, OrderedDict([(1, (10, 41)), (12, (20, 42))])), ]) index2.rebuild(data) assert index2.key_pos == 1 assert index2.value_pos == 3 assert len(index2.key.data) == 2 assert len(index2.value.data) == 4 assert len(index2.meta_key) == 2 assert len(index2.meta_value) == 4