def test_order_dns_srv_priority(self): srv = [SRV(10), SRV(0), SRV(10), SRV(20), SRV(100), SRV(5)] loc = Locator() result = loc._order_dns_srv(srv) prio = [res.priority for res in result] sorted = prio[:] sorted.sort() assert prio == sorted
def test_order_dns_srv_priority(self): srv = [ SRV(10), SRV(0), SRV(10), SRV(20), SRV(100), SRV(5) ] loc = Locator() result = loc._order_dns_srv(srv) prio = [ res.priority for res in result ] sorted = prio[:] sorted.sort() assert prio == sorted
def test_order_dns_srv_weight(self): n = 10000 w = (100, 50, 25) sumw = sum(w) count = {} for x in w: count[x] = 0 loc = Locator() srv = [SRV(0, x) for x in w] for i in range(n): res = loc._order_dns_srv(srv) count[res[0].weight] += 1 print count def stddev(n, p): # standard deviation of binomial distribution return math.sqrt(n * p * (1 - p)) for x in w: p = float(x) / sumw # 6 sigma this gives a 1 per 100 million chance of wrongly # asserting an error here. assert abs(count[x] - n * p) < 6 * stddev(n, p)
def test_order_dns_srv_weight(self): n = 10000 w = (100, 50, 25) sumw = sum(w) count = {} for x in w: count[x] = 0 loc = Locator() srv = [ SRV(0, x) for x in w ] for i in range(n): res = loc._order_dns_srv(srv) count[res[0].weight] += 1 print count def stddev(n, p): # standard deviation of binomial distribution return math.sqrt(n*p*(1-p)) for x in w: p = float(x)/sumw # 6 sigma this gives a 1 per 100 million chance of wrongly # asserting an error here. assert abs(count[x] - n*p) < 6 * stddev(n, p)