Exemple #1
0
    def test_pop(self):
        q = Queue()
        self.assertTrue(q.empty())
        q.append("1")
        self.assertFalse(q.empty())

        self.assertEqual("1", q.pop())
        self.assertTrue(q.empty())
        q.append("2")
        self.assertFalse(q.empty())
        q.append("3")
        q.append("4")
        q.append("5")
        q.append("6")

        self.assertFalse(q.empty())
        self.assertEqual("2", q.pop())
        self.assertEqual("3", q.pop())
        self.assertEqual("4", q.pop())
        self.assertEqual("5", q.pop())
        self.assertFalse(q.empty())
        self.assertEqual("6", q.pop())
        self.assertTrue(q.empty())
Exemple #2
0
def bfs_no_tunneling(filename, env):
    # stats
    max_coverage = 0
    nodes_cnt = 0
    start_time = time.time()
    print_time = time.time() - 2

    # state
    queue = Queue()
    hashes = set()
    queue.append(env.get_init_state())  # push the initial state
    while not queue.empty():
        state = queue.pop()
        nodes_cnt = nodes_cnt + 1
        if time.time() > print_time + 1:
            if env.coverage(state) * 100 > max_coverage:
                max_coverage = env.coverage(state) * 100
            history = state.get_history()
            print_status(filename, -1, int(time.time() - start_time),
                         max_coverage, len(hashes), queue.items, nodes_cnt,
                         len(history), 0)
            print_time = time.time()
            nodes_cnt = 0
        possible_moves = env.nodes[state.pos].keys()
        for op in possible_moves:
            new_state = env.do_step(op=op, state=state)
            new_state_hash = env.state_hash(new_state)
            if new_state_hash in hashes:
                continue
            if env.goal_reached(new_state):
                clean_status()
                return new_state
            hashes.add(new_state_hash)
            queue.append(new_state)
    clean_status()
    return None
Exemple #3
0
from __future__ import print_function

import time

from myqueue import Queue

Q = Queue()

Q.append(10)
Q.append(20)
print(Q.peek())
print(Q.pop())
print(Q.pop())
try:
    print(Q.pop())
except IndexError as e:
    print("Error message:", e)  # Prints "Queue is empty"

i = 10000

values = range(i)

start_time = time.time()

Q.extend(values)

end_time = time.time() - start_time

print("Adding {} items took {:1.3f} msecs.".format(i, 1000 * end_time))

for i in range(41):
from myqueue import Queue

queue1 = Queue()
queue1.push("Ranjeet")
print(queue1.pop())
print(queue1.pop())