Kotlinlearncs.online LogoJava
Return to List

Test Writing: Reverse Stack with Queue

Created By: Justin Maier
/ Version: 2024.10.0

Complete the method below that reverses the order of elements in a Stack<Integer>. Use a Queue to accomplish this. Our Queue has the following interface.

Additionally, you are provided with an implementation of the MyQueue named ArrayListQueue. This queue does not have a fixed capacity. You can create a new instance of the queue with MyQueue<Integer> q = new ArrayListQueue<>();.

Additionally, if the passed stack is null, throw an IllegalArgumentException.

Test Design Challenge

You're challenge is to write tests for this problem described above.

  • Provide a method named test that accepts no arguments and does not return a value.
  • If the implementation of the class described above is incorrect, your test method should throw an exception.
  • If it is correct, do not throw an exception.
  • You may want to use Java's assert method
void reverseStack(Stack<Integer> stack) {
return; // You may need to remove this starter code
}