Contact Us
Order Here
Get Help
More
English
Español
Português
Français
Deutsch
Italiano
Русский
close
Contact Us
Order Here
Get Help
Starting from:
$30
$24
Buy now
Assignment 1 Junit Test Solution
Part I: You are given the following LinkedStack.java file which includes the implementation of Stack using LinkedList data structure.
import java.util.NoSuchElementException;
public class LinkedStack<Item{
private int n; // size of the stack
private Node first; // top of stack
private class Node {
private Item item;
private Node next;
}
//initializes an empty stack.
public LinkedStack() {
first = null;
n = 0;
}
//returns true if this stack is empty; false otherwise
public boolean isEmpty() {
return first == null;
}
//returns the number of items in the stack.
public int size() {
return n;
}
//inserts an item to the stack
public void push(Item item) {
Node temp = first;
first = new Node();
first.item = item;
first.next = temp;
n++;
}
//removes and returns the top element in the stack
public Item pop() {
if (isEmpty()) throw new ArrayIndexOutOfBoundsException("Stack underflow");
Item item = first.item;
first = first.next;
return item;
}
//returns (but does not remove) the item most recently added to this stack.
public Item peek() {
if (isEmpty()) throw new ArrayIndexOutOfBoundsException("Stack underflow");
return first.item;
}
}
You are supposed to use Junit5 to create a test class with test cases, LinkedStackTest.java, to test the operations of LinkedStack.
Here are some other requirements for the activity:
Create a LinkedStackTest.java and write test cases to test all the operations of LinkedStack.java
Pushing 10000 objects into a stack should not take longer than 5 miliseconds
Pop and peek methods should throw NoSuchElementException
if stack is empty
Provide the list of failing test cases and explain the reason for failure
Resolve the issues by modifying the original class in a separate class LinkedStackFixed.java file and make sure all tests pass.
$30
Starting from:
$24
Buy now
1 file (41.9KB)
More products
$6.00 OFF
Discussion 6
$35
$29
Buy now
$6.00 OFF
Discussion 5
$35
$29
Buy now
$6.00 OFF
HW 5
$30
$24
Buy now