W02 Code: Queues
Overview
This assignment must be completed individually to ensure you are meeting all course outcomes. You should not complete this assignment with a group. If you obtain help from a tutor, the tutor should help you understand principles but should not help you answer these problems. It is an honor code violation to obtain answers for these problems from others including using the internet (i.e. sites that allow students to share their solutions).
Running and Debugging
-
You should not edit any files that have the comment
DO NOT MODIFY THIS FILE
at the top of them. Any edits you make to these files will be removed before grading. - Running all tests for this assignment: Click on Run and Debug in the sidebar, then select this week's code assignment from the drop-down at the top. Click the green Start Debugging button next to the drop-down. The integrated terminal will show the files being compiled and then the tests being run. It will print a summary of which tests passed and failed.
-
Running individual tests: Navigate to the test file ending in
_Tests.cs
in the week's code directory. Visual Studio Code will show inline buttons to Run Test for each test method, or to Run All Tests for each test class. -
Debugging individual tests: Navigate to the test file ending in
_Tests.cs
in the week's code directory. Visual Studio Code will show inline buttons to Debug Test for each test method, or to Debug All Tests for each test class.- If you put a breakpoint inside your code or inside the test, the only way to hit it will be by clicking Debug Test or Debug All Tests in this file.
-
If you want to debug by printing output to the terminal, you must use
Debug.WriteLine()
to do so. Using that may require you to addusing System.Diagnostics;
to the top of the file. UsingConsole.WriteLine()
, as is done in other parts of the template project, will not correctly print output to the console when a test is running. Any output generated withDebug.WriteLine()
will appear in the Debug Console portion of the integrated terminal when clicking Debug Test or Debug All Tests in this file.
Instructions
All of the coding files for this assignment will be found in the course week02/code
folder in the course repository. You will commit changes to your own repository and push them to GitHub for your submission for this assignment.
For this assignment, you will write test cases and results directly in the test methods of the appropriate*_Tests.cs
files.
Taking Turns Queue
- Examine the following code file:
TakingTurnsQueue_Tests.cs
(Note: Do not read through the referenced code first. Instead, proceed with the instructions below). - The
TakingTurnsQueue
class maintains a circular queue of people. When a person is added, they are assigned a number of turns (a value of 0 or less means that they have an infinite number of turns). When a person is removed from the queue, they are re-added to the queue if they still have turns left. Here are the detailed requirements (which cannot be changed):- The
AddPerson
function shall enqueue a person into the queue. - The
GetNextPerson
function shall dequeue a person from the queue and return them. - When a person is dequeued and still has turns left, they shall be enqueued again.
- When a person is dequeued and has an infinite number of turns (defined as having number of turns of 0 or less), they shall be enqueued again.
- If the queue is empty, then an error exception shall be thrown.
- The
- Test cases are already written for you in the code. Run the tests and find the errors.
- Summarize the results of the tests and the errors found within the test case documentation above each test case. Do not change the code of the test cases themselves.
- Fix the code so that all requirements are implemented correctly. You know that you are done because the provided test cases will all pass.
Priority Queue
- Examine the following code file:
PriorityQueue_Tests.cs
(Note: Do not read through the referenced code first. Instead, proceed with the instructions below). - The
PriorityQueue
class maintains a queue where each value put in the queue also has a priority (higher numbers have a higher priority). When you add to the queue, it goes to the back as expected. When you remove from the queue, the highest priority item is removed. If there are multiple values with the same high priority, then the first one (following the FIFO strategy) is removed first. Here are the detailed requirements (which cannot be changed):- The
Enqueue
function shall add an item (which contains both data and priority) to the back of the queue. - The
Dequeue
function shall remove the item with the highest priority and return its value. - If there are more than one item with the highest priority, then the item closest to the front of the queue will be removed and its value returned.
- If the queue is empty, then an error exception shall be thrown.
- The
- Write your own test cases based on these requirements within the test case documentation in
PriorityQueue_Tests.cs
. Ensure that your tests cover all of the requirements listed above. - Run your test cases and find the errors. If your tests were not sufficient, you might not find all the errors in the code. You should summarize the results of the tests and the errors found within the test case documentation above each test case.
- Fix the code so that all requirements are implemented correctly. You know that you are done because the test cases will all pass (assuming your test cases were sufficient).
Submission
When you have finished the assignment:
- Make sure that all of your changes are committed to your course repository.
- Push your latest changes to GitHub.
- Return to I-Learn to submit a link to your GitHub repository.