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: 3812207 • 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

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

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;

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; //first

   protected DLLNode<T> end; //last

   // 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; //backe should be initialized to end here anyway

      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 size() function");

      System.out.print("Size of the list is " + dlList.size());

      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());

      System.out.println(" Testing conatains()");

      System.out.print("List contains 35: " + dlList.contains(35));

      System.out.print("List contains 50: " + dlList.contains(50));

      System.out.println(" Testing get()");

      System.out.print(" List get(12): " + dlList.get(12));

      System.out.print(" List get(70): " + dlList.get(70));

      System.out.println(" Testing delete()");

      System.out.print(" List delete(12): " + dlList.delete(12));

      System.out.print(" List delete(70): " + dlList.delete(70));

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

      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.print(" " + dlList.returnNext().intValue());

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

      System.out.print(" " + dlList.getPrevious().intValue()); // error here, node 70 is still available here

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

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

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

      dlList.backReset();

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

      System.out.print(" " + dlList.getPrevious().intValue()); // error here, node 70 is still available here

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

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

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

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

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

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

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

      System.out.print(" " + dlList.getPrevious().intValue()); // 10 is missed

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

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

      dlList.reset();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

     

   }

}

I have added test cases and also marked the errors that are present int the code according to me. I hope you will appreciate the code and hard work. :)

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