java please! This test method is for the pop method from stack. The [returnedVal
ID: 3732263 • Letter: J
Question
java please! This test method is for the pop method from stack. The [returnedValue] below refers to a position object(containing x and y coordinates).
testPopFromEmpty1() is a private test method that creates a new stack and (in a try block) immediately calls pop(). If an EmptyStackException is thrown, then the test passes and this test method returns true. Otherwise, the value pop() returned is saved and the following is printed: “Failure: pop from an empty stack. Expected EmptyStackException. Got [returnedValue].”
Explanation / Answer
private boolean testPopFromEmpty1() { Stack stack = new Stack(); try { System.out.println("Failure: pop from an empty stack. Expected EmptyStackException. Got " + stack.pop() + "."); return false; } catch (Exception e) { return true; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.