java - Unit Test for 'Merge Sort on doubly linked list' -


need create unit test please when created unit test, shows error "no parameters allowed in test"

package mergedoublyll;  import java.util.arraylist; import java.util.iterator;  public class doublell {      static node head;      static class node {          int data;         node next, prev;          node(int d) {             data = d;             next = prev = null;         }     }      node split(node head) {         node fast = head, slow = head;         while (fast.next != null && fast.next.next != null) {             fast = fast.next.next;             slow = slow.next;         }         node temp = slow.next;         slow.next = null;         return temp;     }      node mergesort(node node) {         if (node == null || node.next == null) {             return node;         }         node second = split(node);          node = mergesort(node);         second = mergesort(second);          return merge(node, second);     }      node merge(node first, node second) {         if (first == null) {             return second;         }          if (second == null) {             return first;         }          if (first.data < second.data) {             first.next = merge(first.next, second);             first.next.prev = first;             first.prev = null;             return first;         } else {             second.next = merge(first, second.next);             second.next.prev = second;             second.prev = null;             return second;         }     }     int[] print(node node) {         int a;         arraylist<integer> al = new arraylist<integer>();         node temp = node;         system.out.println("forward traversal using next pointer");         while (temp != null) {             a=(temp.data);             al.add(a);             temp = temp.next;         }         int[] ret = new int[al.size()];         iterator<integer> iterator = al.iterator();         (int = 0; < ret.length; i++)         {             ret[i] = iterator.next().intvalue();         }         return ret;     }     public static void main(string[] args) {          doublell list = new doublell();         doublell.head = new node(10);         doublell.head.next = new node(30);         doublell.head.next.next = new node(3);         doublell.head.next.next.next = new node(4);         doublell.head.next.next.next.next = new node(20);         doublell.head.next.next.next.next.next = new node(5);          node node;         node=head;         node = list.mergesort(head);         system.out.println("linked list after sorting :");         int[] result =list.print(node);         (int j=0; j<result.length;j++)             system.out.print(result[j]);     } } 

unit test:

// unit test  package mergedoublyll;  import static org.junit.assert.assertarrayequals;  import org.junit.test;  import mergedoublyll.doublell.node;  public class testdoublell {      @test     public void test(node head) {         doublell list = new doublell();         doublell.head = new node(10);         doublell.head.next = new node(30);         doublell.head.next.next = new node(3);         doublell.head.next.next.next = new node(4);         doublell.head.next.next.next.next = new node(20);         doublell.head.next.next.next.next.next = new node(5);          node node=head;         node = list.mergesort(head);         int result[] =list.print(node);         int expectedarray[] = {3,4,5,10,20,30};         assertarrayequals(expectedarray, result);     }  } 

unit test should test single unit of code independently else. passing in argument test:

@test public void test(node head) { 

instead create head node inside test , don't have arguments:

@test public void test() { 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -