Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Test plan: either a detailed list of test cases to execute, or a detailed descri

ID: 3812717 • Letter: T

Question

Test plan: either a detailed list of test cases to execute, or a detailed description of your approach to testing your implementation (paragraph form)

DLLNode.JAVA

package ddladt;

public class DLLNode<T>

{

private DLLNode<T> next,back;

private T info;

public DLLNode(T info)

{

this.info = info;

next = null;

}

public void setInfo(T info)

{

this.info = info;

}

public T getInfo()

{

return info;

}

public void setNext(DLLNode<T> next)

{

this.next = next;

}

public DLLNode<T> returnNext()

// Returns next link of this DLLNode.

{

return next;

}

public void setBack(DLLNode<T> back)

{

this.back = back;

}

public DLLNode<T> getBack()

{

return back;

}

}

DLLAdt.JAVA

package ddladt;

public class DLLAdt<T>

{

protected int elemNum;

protected DLLNode<T> current;

protected DLLNode<T> backCurrent;

protected boolean status;

protected DLLNode<T> pos;

protected DLLNode<T> backe;

protected DLLNode<T> dlList;

protected DLLNode<T> end;

//class constructor

public DLLAdt()

{

elemNum = 0;

dlList = null;

end = null;

current = null;

backCurrent = null;

}

//to insert to dd list

public void add(T element)

{

DLLNode<T> newNode = new DLLNode<T>(element);

if(dlList==null)

{

dlList = newNode;

end = dlList;

}

else

{

dlList.setBack(newNode);

newNode.setNext(dlList);

dlList = newNode;

}

elemNum++;

}

protected void find(T target)

{

pos = dlList;

status = false;

while (pos != null)

{

if (pos.getInfo().equals(target))

{

status = true;

return;

}

else

{

backe = pos;

pos = pos.returnNext();

}

}

}

//to get the size

public int size()

{

return elemNum;

}

//to check the presence of an entry

public boolean contains (T element)

{

find(element);

return status;

}

//to delete entries from the list

public boolean delete (T element)

{

find(element);

if (status)

{

if (dlList == pos)  

dlList = dlList.returnNext();

else

backe.setNext(pos.returnNext());

elemNum--;

}

return status;

}

public T get(T element)

{

find(element);

if (status)

return pos.getInfo();

else

return null;

}

public String toString()

{

DLLNode<T> currNode = dlList;

String listString = "List: ";

while (currNode != null)

{

listString = listString + " " + currNode.getInfo() + " ";

currNode = currNode.returnNext();

}

return listString;

}

//reset teh list

public void reset()

{

current = dlList;

}

public void backReset()

{

backCurrent = end;

}

public T returnNext()

{

T next = current.getInfo();

if (current.returnNext() == null)

current = dlList;

else

current = current.returnNext();

return next;

}

//get previous

public T getPrevious()

{

T pre = backCurrent.getInfo();

if (backCurrent.getBack() == dlList)

backCurrent = end;

else

backCurrent = backCurrent.getBack();

return pre;

}

}

Test.JAVA

package ddladt;

//The driver program

public class Test

{

public static void main(String args[])

{

DLLAdt<Integer> dlList= new DLLAdt<Integer>();

for(int itr=100;itr>1;itr-=10)

    dlList.add(itr);

System.out.println(dlList.toString());

dlList.reset();

dlList.backReset();

System.out.println(" Testing the returnNext() function");

System.out.print(" "+dlList.returnNext().intValue());

System.out.print(" "+dlList.returnNext().intValue());

System.out.print(" "+dlList.returnNext().intValue());

System.out.println(" Testing the getPrevious() function");

System.out.print(" "+dlList.getPrevious().intValue());

System.out.print(" "+dlList.getPrevious().intValue());

System.out.print(" "+dlList.getPrevious().intValue());

}

}

Explanation / Answer

Explanation:


This JAVA program is something like a implememation of user defined Arraylist API.

When we compare the JAVA ArrayList API with our customized JAVA API, The below comparision can be done.

1. List definition

DLLAdt<Integer> dlList = new DLLAdt<Integer>();

Equals to

ArrayList<Integer> integerList = new ArrayList<Integer>();

2. add method implememation

dlList.add();

Equals to

integerList.add()

3. Next element function implememation

dlList.returnNext().intValue()

Equals to

Iterator it=integerList.iterator();
it.hasNext()

4. Previous element function implememation

dlList.getPrevious().intValue()

Equals to

Iterator it=integerList.iterator();
it.hasPrevious();
it.previous();


TestCases:

1. DLLAdt size with zero elements, should be failed at runtime.

-> Step 1 : Update the for loop to below
   for (int itr = 0; itr > 1; itr -= 10) {
          dlList.add(itr);
       }
   -> Step 2 : Verify the exception, should be null pointer exception at DLLAdt.java:102
     
2. DDLADt size shoule be 10 elements as mentione in JAVA program

-> Step 1 : Check the loop should start with 100
       for (int itr = 100; itr > 1; itr -= 10) {
          dlList.add(itr);
       }
                     
       -> Step 2 : Out put should print the First three and last three in list.
         
               Expected output :
               List: 10 20 30 40 50 60 70 80 90 100

                                   Testing the returnNext() function
                                   10 20 30
                                   Testing the getPrevious() function
                                   100 90 80
3. DDLADt size shoule be more than 10 elements.
-> Step 1 : Check the loop should start with 1000
       for (int itr = 1000; itr > 1; itr -= 10) {
          dlList.add(itr);
       }
                     
       -> Step 2 : Out put should print the First three and last three in list.
         
               Expected output :
               List: 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200

                                   Testing the returnNext() function
                                   10 20 30
                                   Testing the getPrevious() function
                                   200 190 180
                  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote