コード例 #1
0
ファイル: queues_test.py プロジェクト: cornell-brg/pymtl
def test_Queue( size ):

  # Create the queue
  queue = Queue( size )

  # Fill up the queue
  for i in range( size ):
    queue.enq( i )
    assert queue.peek()     == 0
    assert queue.is_empty() == False

  # Check the queue is full
  assert queue.is_full()

  # Check enqueuing throws an assert
  with pytest.raises( AssertionError ):
    queue.enq( 0 )

  # Empty the queue, check the order is correct
  for i in range( size ):
    assert queue.deq()     == i
    assert queue.is_full() == False

  # Check the queue is empty
  assert queue.is_empty()

  # Check that dequeuing throws an assert
  with pytest.raises( IndexError ):
    queue.deq()
コード例 #2
0
def test_Queue(size):

    # Create the queue
    queue = Queue(size)

    # Fill up the queue
    for i in range(size):
        queue.enq(i)
        assert queue.peek() == 0
        assert queue.is_empty() == False

    # Check the queue is full
    assert queue.is_full()

    # Check enqueuing throws an assert
    with pytest.raises(AssertionError):
        queue.enq(0)

    # Empty the queue, check the order is correct
    for i in range(size):
        assert queue.deq() == i
        assert queue.is_full() == False

    # Check the queue is empty
    assert queue.is_empty()

    # Check that dequeuing throws an assert
    with pytest.raises(IndexError):
        queue.deq()
コード例 #3
0
    def are_connected(self, person1, person2):
        queue = Queue()
        seen = set()
        queue.enqueue(person1)

        while not queue.is_empty():
            current = queue.dequeue()
            seen.add(current)
            print("current:", current)
            print("seen:", seen)
            if current is person2:
                return True
            for adjacent in current.adjacent:
                queue.enqueue(adjacent)
        
        return False