Question
JUnit test not passing. Please explain why, and what to do in order to fix it. Thanks Here's my code: ///////////////////////////////////// package com.mycompany.project_4; /** *
JUnit test not passing. Please explain why, and what to do in order to fix it. Thanks
Here's my code:
/////////////////////////////////////
package com.mycompany.project_4;
/** * * @author yuqin */ public class ArrayQueue implements Queue { private Q[] list; private int size; private int front = 0; private int rear = 0;
/** * this method creates a constructor with capacity = 10 */ public ArrayQueue() { list = (Q[]) new Object[10]; size = 0; }
/** * @return int, the size of the queue * this method returns the size of the queue */ @Override public int size() { //return (rear - front + size) % size; return size; }
/** * @return Boolean, if the queue isEmpty * this method determines if the queue isEmpty */ @Override public boolean isEmpty() { //return front == (rear + 1) % size; //return rear == front; return size == 0; }
/** * @return Boolean * this method determines if the queue isFull */ public boolean isFull() { return size == list.length; }
/** * @return int * this method resizes the queue */ public int resize() { if (isFull()) { Q[] newData = (Q[]) new Object[list.length * 2]; for (int i = 0; i
/** * @param element * @throws com.mycompany.project_4.InvalidDataException * this method add data to the queue */ @Override public void enqueue(Q element) throws InvalidDataException { if (element == null) { throw new InvalidDataException(); } else if (isFull()) { resize(); front = 0; } else { list[rear] = element; rear = (rear + 1) % list.length; size++; } }
/** * @return tempData * @throws com.mycompany.project_4.QueueEmptyException * this method remove data from the queue */ @Override public Q dequeue() throws QueueEmptyException { if (!isEmpty()) { Q tempData = list[front]; list[front] = null; front = (front + 1) % (list.length); size--; return tempData; } else { throw new QueueEmptyException(); } }
/** * @return list[0] * @throws com.mycompany.project_4.QueueEmptyException * this method returns the front element of the queue */ @Override public Q front() throws QueueEmptyException { if (isEmpty()) { throw new QueueEmptyException(); } return list[0]; }
/** * @return String * @throws QueueEmptyException * this method returns all element of list */ public String getQueue() throws QueueEmptyException { if (isEmpty()) { throw new QueueEmptyException(); } else { for (int i = 0; i
}
/////////////////////////////////////////
/** * test if the queue resize when it isFull during the enqueue process * @throws InvalidDataException */ @Test public void testEnqueueWhenQueueIsFull() throws InvalidDataException{ ArrayQueue aq = new ArrayQueue(); for(int i = 0; i
//////////////////////////////
Output Test Results x com.mycompany:Project_4.jar:1.0-SNAPSHOT (Unit) X Tests passed: 93.33% testEnqueueWhenQueuelsFull Failed: expected: but was: expected: but was: org.opentest4j.Assertion Failed Error at org.junit.jupiter.api.Assertion Utils.fail(Assertion Utils.java:55) at org.junit.jupiter.api.Assertion Utils.faillotEqual(Assertion Utils.java:62) at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150) at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:145) Output Test Results x com.mycompany:Project_4.jar:1.0-SNAPSHOT (Unit) X Tests passed: 93.33% testEnqueueWhenQueuelsFull Failed: expected: but was: expected: but was: org.opentest4j.Assertion Failed Error at org.junit.jupiter.api.Assertion Utils.fail(Assertion Utils.java:55) at org.junit.jupiter.api.Assertion Utils.faillotEqual(Assertion Utils.java:62) at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150) at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:145)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started