Question: Please create unit tests for those three functions below. class MyLinkedListTest { @Test void testContainsSubsequence ( ) { } void testRemoveMaximumValues ( ) { }

Please create unit tests for those three functions below.
class MyLinkedListTest
{
@Test
void testContainsSubsequence
(
)
{
}
void testRemoveMaximumValues
(
)
{
}
void testReverse
(
)
{
}
}
public void reverse(){
if (head == null || head.next == null){
return;
}
Node prev = null;
Node current = head;
Node next = null;
while (current != null){
next = current.next;
current.next = prev;
prev = current;
current = next;
}
head = prev;
}
public Boolean containsSubsequence(MyLinkedList two){
if (two == null){
return null; // Return null if 'two' is null
}
if (two.head == null){
return true; // An empty subsequence is always contained
}
Node current = head;
while (current != null){
Node subCurrent = current;
Node otherCurrent = two.head;
// Try to match the sequence starting from current
while (subCurrent != null && otherCurrent != null && subCurrent.value.equals(otherCurrent.value)){
subCurrent = subCurrent.next;
otherCurrent = otherCurrent.next;
}
// If we matched the entire 'two' list, return true
if (otherCurrent == null){
return true;
}
current = current.next;
}
return false; // No match found
}
public void removeMaximumValues(int N){
/* IMPLEMENT THIS METHOD! */
MyLinkedList list = this;
if(list == null || N <=0){
return;
}
//find the maximum
java.util.PriorityQueue maxValues = new java.util.PriorityQueue(java.util.Collections.reverseOrder());
Node current = head;
while (current != null){
if (!maxValues.contains(current.value)){
maxValues.add(current.value);
}
if (maxValues.size()> N){
maxValues.poll();
}
current = current.next;
}
current = head;
Node prev = null;
while (current != null){
if (!maxValues.contains(current.value)){
if (current == head){
removeFirst();
current = head;
} else if (current == tail){
removeLast();
current = null;
} else {
prev.next = current.next;
current = current.next;
size--;
}
} else {
prev = current;
current = current.next;
}
}
}

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!