def test_one_record_with_zero_weight(self): h1 = (1, ) records = [ (0, 0, h1), ] self.assertSequenceEqual( [h1], list(network.group_and_order_srv_records(records)))
def test_equal_prio_weight_and_uncomparable_object(self): o1, o2, = object(), object() records = [ (0, 0, o1), (0, 0, o2), ] self.assertSequenceEqual( [o1, o2], list(network.group_and_order_srv_records(records)))
def test_one_record_with_zero_weight(self): h1 = (1,) records = [ (0, 0, h1), ] self.assertSequenceEqual( [h1], list(network.group_and_order_srv_records(records)) )
def test_group_by_priority(self): hosts = tuple(range(3)) records = [ (0, 0, hosts[0]), (1, 0, hosts[1]), (2, 0, hosts[2]), ] self.assertSequenceEqual( hosts, list(network.group_and_order_srv_records(records)))
def test_equal_prio_weight_and_uncomparable_object(self): o1, o2, = object(), object() records = [ (0, 0, o1), (0, 0, o2), ] self.assertSequenceEqual( [o1, o2], list(network.group_and_order_srv_records(records)) )
def test_group_by_priority(self): hosts = tuple(range(3)) records = [ (0, 0, hosts[0]), (1, 0, hosts[1]), (2, 0, hosts[2]), ] self.assertSequenceEqual( hosts, list(network.group_and_order_srv_records(records)) )
def _test_monte_carlo_ex(self, hosts, records, N=100): rng = random.Random() rng.seed(1234) host_map = {host: collections.Counter() for host in hosts} sum_of_weights = sum(weight for _, weight, _ in records) for i in range(0, sum_of_weights * N): result = network.group_and_order_srv_records(records, rng=rng) for i, host in enumerate(result): host_map[host][i] += 1 return { host: { index: round(indicies[index] / (N * sum_of_weights), 2) for index in range(0, len(records)) } for host, indicies in host_map.items() }
def _test_monte_carlo_ex(self, hosts, records, N=100): rng = random.Random() rng.seed(1234) host_map = { host: collections.Counter() for host in hosts } sum_of_weights = sum(weight for _, weight, _ in records) for i in range(0, sum_of_weights*N): result = network.group_and_order_srv_records(records, rng=rng) for i, host in enumerate(result): host_map[host][i] += 1 return { host: { index: round(indicies[index]/(N*sum_of_weights), 2) for index in range(0, len(records)) } for host, indicies in host_map.items() }