Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop JUnit tests for the BoundedQueueTest class, which is attached to this assignment. Make sure that your tests check every method in this class (Hint:

Develop JUnit tests for the BoundedQueueTest class, which is attached to this assignment. Make sure that your tests check every method in this class (Hint: you can try to come up at least 11 test cases that include expectational and normal behaviors). Submit the code for a Junit test class.
 Attached Assignment Part public class BoundedQueue { // Overview: a BoundedQueue is a mutable, bounded FIFO data structure // of fixed size , with size being set in the constructor // A typical Queue is [], [o1], or [o1, o2], where neither o1 nor o2 // are ever null. Older elements are listed before newer ones. private final Object[] elements; private int size, front, back; private final int capacity; /** * Constructor of BoundedQueue class * @param capacity an integer number indicating the capacity of queue * @throws IllegalStateException if capacity is negative value */ public BoundedQueue(int capacity) { if (capacity < 0) throw new IllegalArgumentException("BoundedQueue.constructor"); this.capacity = capacity; elements = new Object[capacity]; size = 0; front = 0; back = 0; } /** * @param o Object to be inserted in the queue * @throws NullPointerException If argument o is null * @throws IllegalStateException if queue is full */ public void enQueue(Object o) throws NullPointerException, IllegalStateException { // Modifies: this // Effects: If argument is null throw NullPointerException // else if this is full, throw IllegalStateException, // else make o the newest element of this if (o == null) throw new NullPointerException("BoundedQueue.enQueue"); else if (size == capacity) throw new IllegalStateException("BoundedQueue.enQueue"); else { size++; elements[back] = o; back = (back + 1) % capacity; } } /** * @return oldest element of the queue -- Last In First Out (LIFO) * @throws IllegalStateException If queue is empty */ public Object deQueue() throws IllegalStateException { // Modifies: this // Effects: If queue is empty, throw IllegalStateException, // else remove and return oldest element of this if (size == 0) throw new IllegalStateException("BoundedQueue.deQueue"); else { size--; Object o = elements[(front % capacity)]; elements[front] = null; front = (front + 1) % capacity; return o; } } /** * @return true if the queue contains no elements */ public boolean isEmpty() { return (size == 0); } /** * @return true if the queue reaches its maximum capacity */ public boolean isFull() { return (size == capacity); } /** * @return a string representation of the object elements. */ public String toString() { String result = "["; for (int i = 0; i < size; i++) { result += elements[(front + i) % capacity].toString(); if (i < size - 1) { result += ", "; } } result += "]"; return result; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions