コード例 #1
0
 def test_queues(self):
     q = Queue()
     for i in range(1,100):
         q.push(i)
     self.assertEqual(99,q.size())
     self.assertEqual(1,q.peek())
     self.assertEqual(1,q.pop())
コード例 #2
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()
コード例 #3
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()
コード例 #4
0
ファイル: game.py プロジェクト: themeliskalomoiros/bilota
class Table:
    """The table where the Players of the two Teams are sitting, controlling 
    the Players turns."""
    def __init__(self, team1, team2, player_playing_first):
        self.players = [
            team1.player1, team2.player1, team1.player2, team2.player2
        ]

        # Init seats
        self.seats = Queue()
        for p in self.players:
            self.seats.enqueue(p)

        # Set player who plays first next
        while not self.seats.peek() == player_playing_first:
            self.get_next_player()

    def get_next_player(self):
        """Returns the player who plays next."""

        player = self.seats.dequeue()
        self.seats.enqueue(player)

        return player

    def __str__(self):
        p1 = f'{self.players[0]}'
        p2 = f'{self.players[1]}'
        p3 = f'{self.players[2]}'
        p4 = f'{self.players[3]}'

        if p1 == self.seats.peek():
            p1 = f'*{p1}*'
        elif p2 == self.seats.peek():
            p2 = f'*{p2}*'
        elif p3 == self.seats.peek():
            p3 = f'*{p3}*'
        else:
            p4 = f'*{p4}*'

        return f'-- Table --\n\n\t\t\t{p1}\n\n\n\t{p2}\t\t\t{p4}\n\n\n\t\t\t{p3}'