Ejemplo n.º 1
0
    def test_config_from_environment_has_precedence(self):
        from empty import Empty
        from test_empty import config

        os.environ['FLASK_CONFIG'] = os.path\
            .abspath('test_empty/config_set/debug_config.py')
        app = Empty('myapp')
        app.configure(config.EmptyConfig(DEBUG=False))
        self.assertTrue(app.config['DEBUG'])
Ejemplo n.º 2
0
 def dequeue(self):
     if self.is_empty():
         raise Empty('Queue is empty')
     answer = self._head._element
     self._head = self._head._next
     self._size -= 1
     if self.is_empty():
         self._tail = None
     return answer
 def min(self):
     """
     returns: the (k,v) tuple with the minimum key, without removing it
     """
     if self.is_empty():
         raise Empty('Priority Queue is empty')
     p = self._data.first()
     item = p.element()
     return (item._key, item._value)
Ejemplo n.º 4
0
 def dequeue(self):
     """returns: the element removed from the front of the Queue"""
     if self.is_empty():
         raise Empty('The Queue is empty')
     elem = self._data[self._front]
     self._data[self._front] = None
     self._front = (self._front + 1) % len(self._data)
     self._size -= 1
     return elem
Ejemplo n.º 5
0
 def deque(self):
     if self._is_empty():
         raise Empty('empty list')
     else:
         value = self.head.element
         self.head = self.head.next
         self.size -= 1
         if self._is_empty():
             self.tail = None
         return value
Ejemplo n.º 6
0
 def pop(self):
     """Remove and return the element from the top of the stack.
     Raise Empty exception if the stack is empty.
     """
     if self.is_empty():
         raise Empty('Stack is empty!')
     answer = self._head.element
     self._head = self._head.next_node
     self._size -= 1
     return answer
Ejemplo n.º 7
0
    def __init__(self):
        self.empty = Empty(self)
        self.not_empty = NotEmpty(self)
        self.check_out = AtCheckOut(self)
        self.paid_for = PaidFor(self)
        self.suspended = Suspended(self)

        self.items = 0
        self.state = self.empty
        self.suspended_state = None
 def remove_min(self):
     """
     returns: the key-value pair with the minimal key removed from the priority queue
     """
     if self.is_empty():
         raise Empty('Priority Queue is empty')
     self._swap(0, len(self._data) - 1)
     item = self._data.pop()
     self._downheap(0)
     return (item._key, item._value)
 def remove_min(self):
     """
     removes the minimum (k,v) tuple from the priority queue
     returns: the (k,v) tuple
     """
     if self.is_empty():
         raise Empty('Priority Queue is empty')
     p = self._data.first()
     item = self._data.delete(p)
     return (item._key, item._value)
 def dequeue(self):
     if self.is_empty():
         raise Empty('Queue is empty')
     oldhead = self._tail._next
     if self._size == 1:
         self._tail = None
     else:
         self._tail._next = oldhead._next
     self._size -= 1
     return oldhead._element
Ejemplo n.º 11
0
    def test_config_load_blueprint(self):
        from empty import Empty
        from empty import EmptyConfig

        my_config = EmptyConfig(BLUEPRINTS=['app1'])
        my_app = Empty('myapp')
        my_app.configure(my_config)

        self.assertEqual(len(my_config.BLUEPRINTS), 1)
        self.assertEqual(len(my_app.blueprints), 1)
Ejemplo n.º 12
0
    def test_config_load_extension(self):
        from empty import Empty
        from empty import EmptyConfig

        config = EmptyConfig(EXTENSIONS=['extensions.ext'])
        app = Empty('myapp')
        app.configure(config)
        app.setup()
        ext = app.extensions['ext']
        self.assertTrue('test' in ext.options)
Ejemplo n.º 13
0
 def insert(self, e):
     if self.current_size == self.maxsize:
         raise  Empty('no space')
     else:
        self.current_size += 1
        i = self.current_size
        while i != 1 and e > self.data[i//2]:
             self.data[i] = self.data[i//2]
             i = i//2
        self.data[i] = e
Ejemplo n.º 14
0
 def dequeue(self):
     """returns: the element removed from the front of the queue"""
     if self.is_empty():
         raise Empty('The queue is empty')
     removed = self._front._element
     self._front = self._front._next
     self._size -= 1
     if self.is_empty():
         self._rear = None
     return removed
    def pop(self):
        """Return and remove the top element of the stack

        Raise Empty exception if the stack is empty
        """
        if self.is_empty():
            raise Empty('stack is empty')
        answer = self._head._element
        self._head = self._head._next
        self._size -= 1
        return answer
Ejemplo n.º 16
0
 def make_move(self, piece_to):
     if self.can_move(piece_to):
         self.board.history.append('{0}({1}) --> {2}({3})'.format(
             self, self.position, piece_to, piece_to.position))
         self.board[self.position], self.board[piece_to.position] = Empty(
             None, self.board), self.board[self.position]
         if self.first_move:
             self.first_move = False
         if not isinstance(piece_to, Empty):
             self.board.deleted_pieces.append(piece_to)
     else:
         raise Exception('Bishop can\'t move there')
Ejemplo n.º 17
0
 def dequeue(self):
     """Remove and return the first element of the queue.
     Raise Empty exception if the queue is empty.
     """
     if self.is_empty():
         raise Empty('Queue is empty!')
     answer = self._head.element
     self._head = self._head.next_node
     self._size -= 1
     if self.is_empty():
         self._tail = None
     return answer
Ejemplo n.º 18
0
    def _find_min(self):
        """Return Position of item with minimum key."""
        if self.is_empty():
            raise Empty('Priority queue is empty')
        small = self._data.first()
        walk = self._data.after(small)
        while walk is not None:
            if walk.element() < small.element():
                small = walk
            walk = self._data.after(walk)

        return small
    def dequeue(self):
        """Return and remove front element in queue

        Raise Empty exception if queue is empty
        """
        if self.is_empty():
            raise Empty('queue is empty')
        answer = self._head._element
        self._head = self._head._next
        self._size -= 1
        if self.is_empty():
            self._tail = None                                    # removed head was also the tail
        return answer
Ejemplo n.º 20
0
    def dequeue(self):
        if self.is_empty():
            raise Empty('Queue is empty')

        # Pull the current node from the head
        old_head = self._head._link

        # Set the new head to the old heads link
        self._head._link = old_head._link

        self._size -= 1

        return old_head._element
Ejemplo n.º 21
0
 def dequeue(self):
     """
     returns: the element removed from the front of the queue
     """
     if self.is_empty():
         raise Empty('Queue is empty')
     head = self._tail._next
     if self._size == 1:
         self._tail._next = None
     else:
         self._tail._next = head._next
     self._size -= 1
     return head._element
Ejemplo n.º 22
0
	def dequeue(self):
		"""Remove and return the first element of the queue.
		Raise Empty exception if the queue is empty.
		"""
		if self.is_empty():
			raise Empty('Queue is empty!')
		answer = self._data[self._front]
		self._data[self._front] = None
		self._front = (self._front + 1) % len(self._data)
		self._size -= 1
		if 0 < self._size < len(self._data) // 4: # Shrinking the underlying array
			self._resize(len(self._data) // 2)
		return answer
 def dequeue(self):
     """Remove and return the first element of the queue.
     Raise Empty exception if the queue is empty.
     """
     if self.is_empty():
         raise Empty('Queue is empty!')
     oldhead = self._tail.next_node
     if self._size == 1:
         self._tail = None
     else:
         self._tail.next_node = oldhead.next_node
     self._size -= 1
     return oldhead.element
Ejemplo n.º 24
0
    def dequeue(self):
        """Return and remove the front item in the queue

        Raise Empty exception if queue is empty
        """
        if self.is_empty():
            raise Empty('queue is empty')
        answer = self._data[self._front]
        self._data[self._front] = None  # assist garbage collection
        self._front = (self._front + 1) % len(self._data)
        self._size -= 1
        if 0 < self._size < len(self._data) // 4:
            self._resize(len(self._data) // 2)
        return answer
 def _find_min(self):
     """
     Non-public utility method
     returns: the item with the minimum key
     """
     if self.is_empty():
         raise Empty('Priority Queue is empty')
     minimum = self._data.first()
     walk = self._data.after(minimum)
     while walk is not None:
         if walk.element() < minimum.element(
         ):  # __lt__ is implemented by the PriorityQueue class
             minimum = walk
         walk = self._data.after(walk)
     return minimum
Ejemplo n.º 26
0
 def del_max(self):
         if self.current_size == self.maxsize:
            raise  Empty('no space')
         else:
             y = self.data[self.current_size]
             self.current_size -= 1
             i = 1
             ci =2
             while ci <= self.current_size:
                 if ci < self.current_size and self.data[ci] < self.data[ci+1]:
                     ci += 1
                 if y >= self.data[ci]:
                     break
                 self.data[i] = self.data[ci]
                 i = ci
                 ci *= 2
             self.data[i] = y
Ejemplo n.º 27
0
    def __init__(self):

        self.board = [[Empty(x='',y='',sl='.',team='')]*9 for _ in range(9)]
        self.board[0][0] = Rook(x=0,y=0,sl='r',team='black')
        self.board[0][1] = Knight(x=0,y=1,sl='n',team='black')
        self.board[0][2] = Bishop(x=0,y=2,sl='b',team='black')
        self.board[0][3] = Queen(x=0,y=3,sl='q',team='black')
        self.board[0][4] = King(x=0,y=4,sl='k',team='black')
        self.board[0][5] = Bishop(x=0,y=5,sl='b',team='black')
        self.board[0][6] = Knight(x=0,y=6,sl='n',team='black')
        self.board[0][7] = Rook(x=0,y=7,sl='r',team='black')
        self.board[1][0] = Pawn(x=1,y=0,sl='p',team='black')
        self.board[1][1] = Pawn(x=1,y=1,sl='p',team='black')
        self.board[1][2] = Pawn(x=1,y=2,sl='p',team='black')
        self.board[1][3] = Pawn(x=1,y=3,sl='p',team='black')
        self.board[1][4] = Pawn(x=1,y=4,sl='p',team='black')
        self.board[1][5] = Pawn(x=1,y=5,sl='p',team='black')
        self.board[1][6] = Pawn(x=1,y=6,sl='p',team='black')
        self.board[1][7] = Pawn(x=1,y=7,sl='p',team='black')
        self.board[7][0] = Rook(x=7,y=0,sl='R',team='white')
        self.board[7][1] = Knight(x=7,y=1,sl='N',team='white')
        self.board[7][2] = Bishop(x=7,y=2,sl='B',team='white')
        self.board[7][3] = Queen(x=7,y=3,sl='Q',team='white')
        self.board[7][4] = King(x=7,y=4,sl='K',team='white')
        self.board[7][5] = Bishop(x=7,y=5,sl='B',team='white')
        self.board[7][6] = Knight(x=7,y=6,sl='N',team='white')
        self.board[7][7] = Rook(x=7,y=7,sl='R',team='white')
        self.board[6][0] = Pawn(x=3,y=0,sl='P',team='white')
        self.board[6][1] = Pawn(x=6,y=1,sl='P',team='white')
        self.board[6][2] = Pawn(x=6,y=2,sl='P',team='white')
        self.board[6][3] = Pawn(x=6,y=3,sl='P',team='white')
        self.board[6][4] = Pawn(x=6,y=4,sl='P',team='white')
        self.board[6][5] = Pawn(x=6,y=5,sl='P',team='white')
        self.board[6][6] = Pawn(x=6,y=6,sl='P',team='white')
        self.board[6][7] = Pawn(x=6,y=7,sl='P',team='white')

        for i in range(9):
            self.board[i][8 ]= Number(sl=i)
        for j in range(9):
            self.board[8][j] = Number(sl=j)
Ejemplo n.º 28
0
 def __init__(self):
     self.top = Empty()
 def top(self):
     """Return (but do not remove) the top element of the stack"""
     if self.is_empty():
         raise Empty('stack is empty')
     return self._head._element
Ejemplo n.º 30
0
 def top(self):
     if self.is_empty():
         raise Empty('Stack is empty')
     return self._head._element