Example #1
0
class TextStack(unittest.TestCase):

    def setUp(self):
        self.queue = Queue()
        self.queue.put(4)
        self.queue.put(2)
        self.queue.put(1)
        self.queue.put(6)

        self.queueTwo = Queue()
        self.queueTwo.put(1)
        self.queueTwo.put(2)


    def test_put(self):
        self.queue.put(9)
        self.assertEquals(self.queue.__str__(), [4, 2, 1, 6, 9, None])
        with self.assertRaises(IndexError):
            self.queue.put(1)
            self.queue.put(2)

    def test_pop(self):
        self.queueTwo.get()
        self.assertEquals(self.queueTwo.__str__(), [None, 2, None, None, None , None])
        with self.assertRaises(IndexError):
            self.queueTwo.get()
            self.queueTwo.get()
    def test_print(self):
        queue = Queue()

        assert queue.__str__() == ''
        # assert print(queue) == ''

        queue.enqueue(3)
        queue.enqueue(1)
        queue.enqueue(2)

        assert queue.__str__() == '3 -> 1 -> 2'
Example #3
0
def showSummary():
    queues = {}
    slots = {}

    #get the slot info
    slotsData = session.getSlotInfo()
    #add all the slots to our dictionary
    for slotData in slotsData:
        slot = Slot(slotData)
        slots[slot.id] = slot

    #now the queue info
    queuesData = session.getQueueInfo()
    for queueData in queuesData:
        queue = Queue(queueData)
        queues[queue.id] = queue
        #add this queue to it's parent slot's list of queues
        slotID = int(queue.slot)
        slots[slotID].queues.append(queue)

    #get basic details
    teamInfo = eval(session.getPreparedResponse("options user team"), {}, {})

    print("User {user} is folding for team {team}".format(
        user=teamInfo["user"], team=teamInfo["team"]))
    for slot in slots.values():
        print(slot.__str__())
    for queue in queues.values():
        print(queue.__str__())
Example #4
0
def main():
    print('\n\nCreating empty ListStack named "a" of size 4')
    a = ListStack(4)
    print('Creating empty ListQueue named "b" of size 4')
    b = ListQueue(4)
    print('Creating empty Stack named "c" of size 4')
    c = Stack(4)
    print('Creating empty Queue named "d" of size 4')
    d = Queue(4)
    print("")

    print("PEEKING ON AN (a)LISTSTACK, (b)QUEUESTACK, (c)STACK, (d)QUEUE")
    print('peek on a', a.peek(), 'currently contains', a.__str__())
    print('peek on b', b.peek(), 'currently contains', b.__str__())
    print('peek on c', c.peek(), 'currently contains', c.__str__())
    print('peek on d', d.peek(), 'currently contains', d.__str__())
    print("")

    print(
        " ----------- INSERTING VALUES ON (a)LISTSTACK, (b)QUEUESTACK, (c)STACK, (d)QUEUE ---------------"
    )
    for val in range(6):
        print('inserting', val,
              'into both a(ListStack), b(ListQueue), c(Stack), d(Queue)\n')
        print("")
        a.insert(val)
        b.insert(val)
        c.push(val)
        d.enqueue(val)
        print('peek on a', a.peek(), 'currently contains', a.__str__())
        print('peek on b', b.peek(), 'currently contains', b.__str__())
        print('peek on c', c.peek(), 'currently contains', c.__str__())
        print('peek on d', d.peek(), 'currently contains', d.__str__())

    print("")
    print(
        " ----------- REMOVING VALUES ON (a)LISTSTACK, (b)QUEUESTACK, (c)STACK, (d)QUEUE ---------------"
    )
    for i in range(4):
        print('Removing', i,
              'into both a(ListStack), b(ListQueue), c(Stack), d(Queue)')
        print('Before removing', a.peek(), 'from a', a.__str__())
        a.remove()
        print('peek on a', a.peek(), 'after removing', a.__str__())
        print("")

        print('Before removing', b.peek(), 'from b', b.__str__())
        b.remove()
        print('peek on a', a.peek(), 'after removing', b.__str__())
        print("")

        print('Before removing', c.peek(), 'from c', c.__str__())
        c.pop()
        print('peek on c', c.peek(), 'after removing', c.__str__())
        print("")

        print('Before removing', c.peek(), 'from d', d.__str__())
        d.dequeue()
        print('peek on d', c.peek(), 'after removing', d.__str__())
        print("")

    l = [10, 2, 23, 35, 76]
    print(
        " ----------- INSERTING USER DEFINED VALUES ON (a)LISTSTACK, (b)QUEUESTACK, (c)STACK, (d)QUEUE ---------------"
    )
    for val in l:
        print('inserting', val,
              'into both a and b and c which is user defined')
        a.insert(val)
        b.insert(val)
        c.push(val)
        d.enqueue(val)
        print('peek on a', a.peek(), 'currently contains', a.__str__())
        print('peek on b', a.peek(), 'currently contains', b.__str__())
        print('peek on b', c.peek(), 'currently contains', c.__str__())
        print('peek on d', d.peek(), 'currently contains', d.__str__())
        print("")

    print("")
    print(
        " ----------- REMOVING USER DEFINED VALUES ON (a)LISTSTACK, (b)QUEUESTACK, (c)STACK, (d)QUEUE ---------------"
    )
    for i in l:
        print('Removing', i,
              'into both a(ListStack), b(ListQueue), c(Stack), d(Queue)')
        print('Before removing', a.peek(), 'from a', a.__str__())
        a.remove()
        print('peek on a', a.peek(), 'after removing', a.__str__())
        print("")

        print('Before removing', b.peek(), 'from b', b.__str__())
        b.remove()
        print('peek on a', a.peek(), 'after removing', b.__str__())
        print("")

        print('Before removing', c.peek(), 'from c', c.__str__())
        c.pop()
        print('peek on c', c.peek(), 'after removing', c.__str__())
        print("")

        print('Before removing', c.peek(), 'from d', d.__str__())
        d.dequeue()
        print('peek on d', c.peek(), 'after removing', d.__str__())
        print("")
Example #5
0
from queue import Queue

q = Queue(3)
assert (q.is_empty())
assert (hasattr(q, "items"))
assert (hasattr(q, "insert"))
assert (hasattr(q, "remove"))
assert (hasattr(q, "is_empty"))

result = q.insert(5)
assert (result == True)
assert (not q.is_empty())
assert (q.__str__() == "5")

result = q.insert(7)
assert (result == True)
assert (not q.is_empty())
assert (q.__str__() == "7 5")

result = q.insert(-1)
assert (result == True)
assert (not q.is_empty())
assert (q.__str__() == "-1 7 5")

result = q.insert(20)
assert (result == False)
assert (not q.is_empty())
assert (q.__str__() == "-1 7 5")

result = q.insert(33)
assert (result == False)
Example #6
0
from queue import Queue

if __name__ == '__main__':
    quwu = Queue()
    print(quwu.isEmpty())
    quwu.enqueue(2)
    quwu.enqueue("Hello")
    print(quwu.__str__())
    print(quwu.size())
    print(quwu.isEmpty())
    print(quwu.front().data)
    quwu.dequeue()
    quwu.dequeue()
    print(quwu.isEmpty())