Question: Please create unit tests for those three functions below. class MyRawLinkedListTest { @Test void testRawContainsSubsequence ( ) { } void testRawRemoveMaximumValues ( ) { }

Please create unit tests for those three functions below.
class MyRawLinkedListTest {
@Test
void testRawContainsSubsequence(){}
void testRawRemoveMaximumValues(){}
void testRawReverse(){}
}
Here are the functions:
public class MyRawLinkedList {
private static final long serialVersionUID =1561306366555780559L;
static class Node {
private static final long serialVersionUID =-3505677833599614054L;
String value;
Node next = null;
Node(String value, Node next){
this.value = value;
this.next = next;
}
Node(String value){
this(value, null);
}
}
/* This is intentionally left private so that you can't erroneously try to
* instantiate a `new MyRawLinkedList()`
*/
private MyRawLinkedList(){}
/*
* These methods included as examples for how to use Node as a linked list.
*/
public static String listToString(Node head){
String ret ="";
while (head != null){
ret +="\""+ head.value +(head.next == null ?"\"" : "\",");
head = head.next;
}
return "["+ ret +"]";
}
public static void print(Node head){
System.out.println(listToString(head));
}
public static void main(String[] args){
Node list1= new Node("One", new Node("Two", new Node("Three", null)));
print(list1);
Node args_as_list = null;
for (int i = args.length -1; i >=0; i--)
args_as_list = new Node(args[i], args_as_list);
print(args_as_list);
Node list2= null;
list2= new Node("a", list2);
list2= new Node("b", list2);
list2= new Node("c", list2);
print(list2);
}
/*
* Implement the methods below. Please do not change their signatures!
*/
public static Node reverse(Node head){
/* IMPLEMENT THIS METHOD! */
Node current = head; // current node that we are on
Node prev = null; // previous node that we have seen
Node next = null; // placeholder for the next node
while (current != null){// while we have not reached the end of the list
next = current.next; // set next to the next node
current.next = prev; // set the next pointer of the current node to the previous node
prev = current; // set prev to the current node
current = next; // set current to the next node
}
head = prev; // set head to the last node we saw, which is prev
return head; // return the head of the reversed list
}
public static Node removeMaximumValues(Node head, int N){
/* IMPLEMENT THIS METHOD! */
// find the maximum value in linked list datas are string type
Node current = head; // current node
String max = current.value; // max value
while (current != null){// loop through the linked list
if (current.value.compareTo(max)>0){// compare the current value with max value
max = current.value; // if current value is greater than max value, then assign current value to max
}
current = current.next; // move to next node
}
// remove the maximum value in linked list
current = head; // current node
Node prev = null; // previous node
while (current != null){// loop through the linked list
if (current.value.equals(max)){// if current value is equal to max value
if (prev == null){// if previous node is null
head = current.next; // assign current node's next node to head
} else {
prev.next = current.next; // assign current node's next node to previous node's next node
}
N--; // decrement N
}
prev = current; // assign current node to previous node
current = current.next; // move to next node
}
return head; // return head
}
public static boolean containsSubsequence(Node head, Node other){
/* IMPLEMENT THIS METHOD! */
if (head == null && other == null){// if both head and other are null
return true;
}
if (head == null || other == null){// if one of head and other is null
return false;
}
// if both head and other are not null
return head.value.equals(other.value) &&
containsSubsequence(head.next, other.next)
|| containsSubsequence(head.next, other);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!