Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.52 KB | None | 0 0
  1. /**
  2.  * Class to test List.java
  3.  * @author Ryan Riley Puzon
  4.  * @author Owehn Lagman
  5.  */
  6. import java.util.NoSuchElementException;
  7.  
  8.  
  9. public class ListTest {
  10.     public static void main(String[]  args) {
  11.         List<Integer> L = new List<Integer>();
  12.         List<Integer> n = new List<Integer>();
  13.         List<Integer> o = new List<Integer>();
  14.        System.out.println("Testing Integers: ");
  15.         System.out.println("Should print nothing (an empty list): " + L);
  16.         System.out.println("**Testing addFirst**");
  17.         L.addFirst(2);
  18.         System.out.println("Should print 2: " + L);
  19.         L.addFirst(1);
  20.         System.out.println("Should print 1 2: " + L);
  21.        
  22.        
  23.        
  24.         //Code to test addLast goes here!
  25.        
  26.         System.out.println("**Testing addlast**");
  27.         n.addLast(5);
  28.         System.out.println("Should print 5: " + n);
  29.         n.addLast(8);
  30.         System.out.println("Should print 5 8: " + n);
  31.        
  32.         System.out.println("**Testing getFirst**");
  33.         System.out.println("Should print 5: " + n.getFirst());
  34.         System.out.println("Should print 1: " + L.getFirst());
  35.        
  36.        
  37.         System.out.println("**Testing getlast**");
  38.         System.out.println("Should print 2: " + L.getLast());
  39.         System.out.println("Should print 8: " + n.getLast());
  40.        
  41.         System.out.println("**Testing getlength**");
  42.         System.out.println("Should print 2: " + L.getLength());
  43.         System.out.println("Should print 2: " + n.getLength());
  44.         System.out.println("Should print 0: " + o.getLength());
  45.        
  46.         System.out.println("**Testing removeFirst**");
  47.         L.removeFirst();
  48.         System.out.println("Should print 2: " + L);
  49.         L.removeFirst();
  50.         System.out.println("Should print an new Line: " + L);
  51.         System.out.println("Should an error message for an empty List: ");
  52.         try {
  53.             L.removeFirst();
  54.         } catch(NoSuchElementException e) {
  55.             System.out.println(e.getMessage());
  56.         }
  57.         //Tests for removeLast go here!
  58.         System.out.println("\n**Testing removeLast**");
  59.         n.removeLast();
  60.         System.out.println("Should print 5: " + n);
  61.         n.removeLast();
  62.         System.out.println("Should print an new Line: " + n);
  63.         System.out.println("Should an error message for an empty List: ");
  64.         try {
  65.             n.removeLast();
  66.         } catch(NoSuchElementException e) {
  67.             System.out.println(e.getMessage());
  68.         }
  69.        
  70.         System.out.println("\n**Testing isEmpty**");
  71.         List<Integer> L2 = new List<Integer>();
  72.         System.out.println("Should print true: " + L2.isEmpty());
  73.         //add another test for isEmpty() here!
  74.         L2.addFirst(2);
  75.         System.out.println("Should print false: " + L2.isEmpty());
  76.    
  77.        
  78.         System.out.println("Testing doubles: ");
  79.         List<Double> A = new List<Double>();
  80.         List<Double> B = new List<Double>();
  81.         List<Double> C = new List<Double>();
  82.        
  83.         System.out.println("should print nothing(empty list of List A: )" + A);
  84.         double a = 1.1;
  85.         double b = 2.2;
  86.         double c = 3.3;
  87.         double d = 4.4;
  88.         double e = 5.5;
  89.         double f = 6.6;
  90.         double g = 7.7;
  91.         A.addFirst(a);
  92.         System.out.println("should print 1.1: " + A);
  93.         A.addFirst(b);
  94.         System.out.println("should print 2.2 then 1.1: " + A);
  95.        
  96.         System.out.println("**Testing addlast**");
  97.         A.addLast(c);
  98.         A.addLast(d);
  99.         System.out.println("should print 2.2 1.1 3.3 4.4: " + A);
  100.        
  101.         System.out.println("**Testing getFirst**");
  102.         System.out.println("should print 2.2 " + A.getFirst());
  103.        
  104.         System.out.println("**Testing getLast**");
  105.         System.out.println("should print 4.4 " + A.getLast());
  106.        
  107.         System.out.println("**Testing getlength**");
  108.         System.out.println("Should print 4: " + A.getLength());
  109.        
  110.         B.addLast(e);
  111.         B.addLast(f);
  112.         B.addLast(g);
  113.        
  114.        
  115.         System.out.println("**Testing removeFirst**");
  116.         B.removeFirst();
  117.         System.out.println("Should print 6.6 7.7: " + B);
  118.         B.removeFirst();
  119.         System.out.println("Should print 7.7: " + B);
  120.        
  121.         C.addFirst(a);
  122.         C.addFirst(c);
  123.         C.addFirst(f);
  124.        
  125.         System.out.println("**Testing removeLast**");
  126.         C.removeLast();
  127.         System.out.println("Should print 6.6 3.3: " + C);
  128.         C.removeLast();
  129.         System.out.println("Should print 6.6: " + C);
  130.        
  131.        
  132.         System.out.println("**Testing Strings**");
  133.        
  134.         List <String> s1 = new List<String>();
  135.         List <String> s2 = new List<String>();
  136.         List <String> s3 = new List<String>();
  137.        
  138.         String a1 = "a1";
  139.         String b1 = "b1";
  140.         String c1 = "c1";
  141.         String d1 = "d1";
  142.         String e1 = "e1";
  143.         String f1 = "f1";
  144.         String g1 = "g1";
  145.        
  146.        
  147.         s1.addFirst(a1);
  148.         System.out.println("should print a1: " + s1);
  149.         s1.addFirst(b1);
  150.         System.out.println("should print b1 then a1: " + s1);
  151.        
  152.         System.out.println("**Testing addlast**");
  153.         s1.addLast(c1);
  154.         s1.addLast(d1);
  155.         System.out.println("should print b1 a1 c1 d1: " + s1);
  156.        
  157.         System.out.println("**Testing getFirst**");
  158.         System.out.println("should print b1 " + s1.getFirst());
  159.        
  160.         System.out.println("**Testing getLast**");
  161.         System.out.println("should print d1 " + s1.getLast());
  162.        
  163.         System.out.println("**Testing getlength**");
  164.         System.out.println("Should print 4: " + s1.getLength());
  165.        
  166.         s2.addLast(e1);
  167.         s2.addLast(f1);
  168.         s2.addLast(g1);
  169.        
  170.        
  171.         System.out.println("**Testing removeFirst**");
  172.         s2.removeFirst();
  173.         System.out.println("should print f1 g1  : " + s2);
  174.         s2.removeFirst();
  175.         System.out.println("Should print g1: " + s2);
  176.        
  177.         s3.addFirst(a1);
  178.         s3.addFirst(c1);
  179.         s3.addFirst(f1);
  180.        
  181.         System.out.println("**Testing removeLast**");
  182.         s3.removeLast();
  183.         System.out.println("Should print f1 c1: " + s3);
  184.         s3.removeLast();
  185.         System.out.println("Should print f1: " + s3);
  186.        
  187.        
  188.         //////// ITERATOR TESTS
  189.         System.out.println("**Testing Iterator Methods**");
  190.        
  191.         List <Integer> dl1 = new List<Integer>();
  192.         dl1.addFirst(3);
  193.         dl1.addFirst(2);
  194.         dl1.addFirst(1);
  195.         System.out.println("Should print 1 2 3: " + dl1);
  196.        
  197.         dl1.pointIterator();
  198.         System.out.println("Testing pointIterator: ");
  199.         System.out.println("Should print 1: " + dl1.getIterator());
  200.         System.out.println("Testing advanceIterator & reverseIterator: ");
  201.         dl1.advanceIterator();
  202.         System.out.println("Should print 2: " + dl1.getIterator());
  203.         dl1.advanceIterator();
  204.         System.out.println("Should print 3: " + dl1.getIterator());
  205.         dl1.reverseIterator();
  206.         dl1.reverseIterator();
  207.         System.out.println("Should print 1: " + dl1.getIterator());
  208.        
  209.        
  210.         List<Integer> dl2 = new List<Integer>();
  211.         System.out.println("Should throw getIterator exception: ");
  212.         try {
  213.             dl2.getIterator();
  214.         } catch(NoSuchElementException ee) {
  215.             System.out.println(ee.getMessage());
  216.         }
  217.        
  218.        
  219.         System.out.println("Testing removeIterator: ");
  220.         dl1.advanceIterator();
  221.         System.out.println("Should print 2: " + dl1.getIterator());
  222.         System.out.println("Iterator pointing at 2. \n");
  223.         System.out.println("Current list: " + dl1);
  224.         dl1.removeIterator();
  225.         System.out.println("Current list after "
  226.                 + "removeIterator called ( should be 1 3): " + dl1);
  227.         dl1.pointIterator();
  228.         dl1.removeIterator();
  229.         System.out.println("Current list after "
  230.                 + "removeIterator called ( should be 3): " + dl1);
  231.        
  232.         System.out.println("Testing addIterator: ");
  233.        
  234.         List<Integer> dl3 = new List<Integer>();
  235.         dl3.addLast(1);
  236.         dl3.addLast(3);
  237.         dl3.addLast(4);
  238.         System.out.println("Should print 1 3 5: " + dl3);
  239.         dl3.pointIterator(); // point at 1
  240.         dl3.advanceIterator(); // point at 3
  241.         dl3.advanceIterator();
  242.         System.out.println("Get Iterator should be at 4: " + dl3.getIterator());
  243.         dl3.addIterator(5); // adding at end of list
  244.         System.out.println("ADDING AT END OF LIST");
  245.         System.out.println("Should print 1 3 4 5: " + dl3);
  246.         dl3.pointIterator(); // point at 1
  247.         dl3.addIterator(2);
  248.         System.out.println("ADDING AT FRONT OF LIST");
  249.         System.out.println("Should print 1 2 3 4 5: " + dl3);
  250.         dl3.advanceIterator(); // point at 2
  251.         dl3.addIterator(22);
  252.         System.out.println("Should print 1 2 22 3 4 5: " + dl3);
  253.         Scheduler mySchedule = new Scheduler();
  254.         mySchedule.app();
  255.        
  256.      
  257.        
  258.        
  259.        
  260.    
  261.        
  262.        
  263.        
  264.        
  265.        
  266.        
  267.        
  268.        
  269.    
  270.        
  271.        
  272.                
  273.        
  274.        
  275.        
  276.        
  277.        
  278.        
  279.        
  280.        
  281.        
  282.        
  283.        
  284.        
  285.        
  286.      
  287.        
  288.        
  289.        
  290.        
  291.        
  292.        
  293.     }
  294. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement