Beispiel #1
0
    def DS_queue(self):
        try:
            length = int(input(" Enter the length of your Queue: "))
        except:
            return self.DS_queue()

        # Queue instantiation with the given length
        queue = Queue(length)

        while True:
            print(
                '\n [QUEUE OPERATIONS] \n\n 1. Enqueue\n 2. Dequeue\n 3. Display\n 4. Count\n 5. Back\n'
            )

            try:
                selectedNumber = int(input("Select a number: "))
            except:
                print("\nPlease enter a valid input\n")
                input("Press [Enter] to continue...")
                self.DS_queue()

            if selectedNumber == 1:
                value = int(
                    input("Enter the value that you want to enqueue: "))
                queue.enqueue(value)
                print("Success!")
                input("Press [Enter] to continue...")

            elif selectedNumber == 2:
                queue.dequeue()
                print("Success!")
                input("Press [Enter] to continue...")

            elif selectedNumber == 3:
                queue.display()
                input("Press [Enter] to continue...")

            elif selectedNumber == 4:
                queue.countQueue()
                input("Press [Enter] to continue...")

            elif selectedNumber == 5:
                self.DS_main()

            else:
                print(
                    "The number you entered is not in the choices... Going back to the main screen instead..."
                )
                input("Press [Enter] to continue...")
                self.DS_main()
Beispiel #2
0
	def test_queue(self):
		queue = Queue(5)

		# Check instantiation default values
		self.assertEqual(queue.front, -1)
		self.assertEqual(queue.rear, -1)
		self.assertEqual(queue.length, 5)
		self.assertEqual(queue.data, [0,0,0,0,0])
		self.assertEqual(queue.count, 0)

		# Check if isEmpty()
		self.assertTrue(queue.isEmpty())
		# Check if isFull()
		self.assertFalse(queue.isFull())

		# Check if enqueue operation is working properly
		queue.enqueue(5)
		self.assertEqual(queue.data, [5,0,0,0,0])

		# Check count again if incremented
		self.assertEqual(queue.count, 1)

		# Check if front and rear is incremented
		self.assertEqual(queue.front, 0)
		self.assertEqual(queue.rear, 0)

		# Enqueue again to check if rear is working properly
		queue.enqueue(6)
		self.assertEqual(queue.rear, 1)
		self.assertEqual(queue.count, 2)

		# Check is countQueue() is working properly
		self.assertEqual(queue.countQueue(), 2)

		# Check if dequeue() is working properly
		queue.dequeue()
		self.assertEqual(queue.data, [0,6,0,0,0])
		self.assertEqual(queue.count, 1)