Esempio n. 1
0
def test():
    q = Queue()
    assert q.is_empty() is True

    q.enqueue(4)
    assert q.items == [4]

    q.enqueue("dog")
    assert q.items == ["dog", 4]

    q.enqueue(True)
    assert q.items == [True, "dog", 4]

    assert q.size() == 3

    assert q.is_empty() is False

    q.enqueue(8.4)
    assert q.items == [8.4, True, "dog", 4]

    assert q.dequeue() == 4

    assert q.dequeue() == "dog"

    assert q.size() == 2
Esempio n. 2
0
    def test_enqueue_dequeue(self):
        queue = Queue()
        values = [10, 20, 30, 40, 50]
        for value in values:
            queue.enqueue(value)

        self.assertEqual(len(values), queue.size())
        for value in values:
            self.assertEqual(value, queue.dequeue())
        self.assertEqual(0, queue.size())
Esempio n. 3
0
    def test_enqueue_dequeue_big(self):
        queue = Queue()
        for i in range(10000):
            queue.enqueue(i + 1)

        for i in range(10000):
            queue.enqueue(queue.dequeue())

        self.assertEqual(10000, queue.size())
Esempio n. 4
0
    def test_rotate(self):
        # Format: Key - offset, value - expected state
        cases = {
            1: [20, 30, 40, 50, 60, 10],
            3: [40, 50, 60, 10, 20, 30],
            8: [30, 40, 50, 60, 10, 20],
            -1: [60, 10, 20, 30, 40, 50],
            -2: [50, 60, 10, 20, 30, 40],
            0: [10, 20, 30, 40, 50, 60],
            12: [10, 20, 30, 40, 50, 60],
        }
        for offset in cases.keys():
            queue = Queue()
            values = [10, 20, 30, 40, 50, 60]
            for value in values:
                queue.enqueue(value)
            queue.rotate(offset)

            expected_values = cases[offset]
            self.assertEqual(len(values), queue.size())
            for value in expected_values:
                self.assertEqual(value, queue.dequeue())