------------------------------------------------------------------------------ --Name: Matt Jenkins -- --Class: CS 240 -- --Date: Oct. 10 2007 -- --Language: ADA -- --Compiler: Gnat -- --Professor: Dr. Adams -- --Executable: testqueue.exe -- ------------------------------------------------------------------------------ --Purpose:This program tests various operations used on queues. -- -- This program will test adding elements to a queue, removing them, -- -- checking to see if the queue is full or empty, checking the size of the -- -- queue and checking the first element in the queue. -- ------------------------------------------------------------------------------ --Input: none -- --Output: none -- ------------------------------------------------------------------------------ -- I have neither given nor received unauthorized aid on this assignment. -- ------------------------------------------------------------------------------ with ourQueue2; with ada.integer_text_io; with ada.text_io; with ada.io_exceptions; procedure testQueue is package boolean_io is new ada.text_io.enumeration_io (enum => boolean); fullOrEmpty : boolean; size : integer; my_Queue : ourQueue2.onewaylistnode; removedValue : integer; firstElement : integer; begin ada.text_io.put_line("This program will test various methods on a queue."); ada.text_io.new_line; ada.text_io.put_line("Making the queue empty."); ourQueue2.makeEmpty(my_Queue); ada.text_io.put_line("Checking size of queue to make sure it is empty."); size := ourQueue2.SizeOfThing(my_Queue); ada.text_io.put("The size of the queue is "); ada.integer_text_io.put(size); ada.text_io.new_line(2); ada.text_io.put_line("Adding elements to fill the queue."); for i in 1..20 loop ourQueue2.addSomething(i, my_Queue); ada.integer_text_io.put(i); ada.text_io.put(" was added to the queue."); ada.text_io.new_line; end loop; ada.text_io.new_line; ada.text_io.put_line("checking to see if the queue is full."); fullOrEmpty := ourQueue2.IsThingFull(my_queue); ada.text_io.put("The queue is full: "); boolean_io.put(fullOrEmpty); ada.text_io.new_line(2); ada.text_io.put_line("Adding an element to a full queue."); ourQueue2.addSomething(1, my_Queue); ada.text_io.new_Line; ada.text_io.new_line; ada.text_io.put_Line("Removing items from the queue."); size := ourQueue2.SizeofThing(my_queue); for i in 1..size loop ourQueue2.RemoveSomething(removedValue, my_queue); ada.text_io.put("The value removed from the queue was "); ada.integer_text_io.put(removedValue); ada.text_io.new_line; end loop; ada.text_io.new_line; ada.text_io.put_line("checking to see if the queue is empty"); fullorEmpty := ourQueue2.isThingEmpty(my_queue); ada.text_io.put("The queue is empty: "); boolean_io.put(fullOrEmpty); ada.text_io.new_line(2); ada.text_io.put_line("Removing an element from an empty queue"); --nothing happens when removing an item from an empty queue ourQueue2.removeSomething(my_queue); --Even though the size of the array is 0, there is still a 20 --left in the queue because there is nothing to write over it ada.text_io.new_line(2); ada.text_io.put_line("Checking first element of an empty queue"); firstElement := ourQueue2.firstThing(my_Queue); exception when CONSTRAINT_ERROR => ada.text_io.put_line("You have attempted to access an item from an empty queue."); ada.text_io.new_line; --gets a number from memory if no value is present ada.text_io.put("The first element of the empty queue is "); ada.integer_text_io.put(firstElement); ada.text_io.new_line(2); ada.text_io.put("This program has ended normally."); end testQueue;