def testIntegers(self): x = np.random.randint(0, 2**15, size=(100, )).astype(int) y = np.sort(x) pq = PriorityQueue() for a in x: pq.push(a) z = np.asarray([pq.pop() for i in range(len(pq))]) z = z.astype(int) assert_array_equal(y, z)
def testIntegers(self): x = np.random.randint(0, 2**15, size=(100,)).astype(int) y = np.sort(x) pq = PriorityQueue() for a in x: pq.push(a) z = np.asarray([pq.pop() for i in range(len(pq))]) z = z.astype(int) assert_array_equal(y, z)
def testObjects(self): x = [3, 1, 1, 2] a = [Comp(i) for i in x] pq = PriorityQueue() for c in a: pq.push(c) y = [pq.pop() for i in range(len(pq))] assert y[2] is a[3] assert y[3] is a[0] assert y[0] is a[1] assert y[1] is a[2]
def testOnePriority(self): n = 100 p = np.random.random(size=(n, )) a = np.random.random(size=(n, )) combined = list(zip(p, a)) pq = PriorityQueue() for pair in combined: pq.push(pair) s = sorted(combined, key=lambda x: x[0]) y = [pq.pop() for i in range(len(pq))] assert_array_equal(s, y)
def testOnePriority(self): n = 100 p = np.random.random(size=(n,)) a = np.random.random(size=(n,)) combined = list(zip(p, a)) pq = PriorityQueue() for pair in combined: pq.push(pair) s = sorted(combined, key=lambda x: x[0]) y = [pq.pop() for i in range(len(pq))] assert_array_equal(s, y)
def testTwoPriorities(self): n = 400 p1 = np.random.randint(0, 5, size=(n, )) p2 = np.random.random(size=(n, )) a = np.random.random(size=(n, )) combined = list(zip(p1, p2, a)) pq = PriorityQueue() for pair in combined: pq.push(pair) s = sorted(combined, key=lambda x: x[0] + x[1]) x = [a[2] for a in s] y = [pq.pop()[2] for i in range(len(pq))] assert_array_equal(x, y)
def testTwoPriorities(self): n = 400 p1 = np.random.randint(0, 5, size=(n,)) p2 = np.random.random(size=(n,)) a = np.random.random(size=(n,)) combined = list(zip(p1, p2, a)) pq = PriorityQueue() for pair in combined: pq.push(pair) s = sorted(combined, key=lambda x: x[0]+x[1]) x = [a[2] for a in s] y = [pq.pop()[2] for i in range(len(pq))] assert_array_equal(x, y)