Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Class to test List.java
- * @author Ryan Riley Puzon
- * @author Owehn Lagman
- */
- import java.util.NoSuchElementException;
- public class ListTest {
- public static void main(String[] args) {
- List<Integer> L = new List<Integer>();
- List<Integer> n = new List<Integer>();
- List<Integer> o = new List<Integer>();
- System.out.println("Testing Integers: ");
- System.out.println("Should print nothing (an empty list): " + L);
- System.out.println("**Testing addFirst**");
- L.addFirst(2);
- System.out.println("Should print 2: " + L);
- L.addFirst(1);
- System.out.println("Should print 1 2: " + L);
- //Code to test addLast goes here!
- System.out.println("**Testing addlast**");
- n.addLast(5);
- System.out.println("Should print 5: " + n);
- n.addLast(8);
- System.out.println("Should print 5 8: " + n);
- System.out.println("**Testing getFirst**");
- System.out.println("Should print 5: " + n.getFirst());
- System.out.println("Should print 1: " + L.getFirst());
- System.out.println("**Testing getlast**");
- System.out.println("Should print 2: " + L.getLast());
- System.out.println("Should print 8: " + n.getLast());
- System.out.println("**Testing getlength**");
- System.out.println("Should print 2: " + L.getLength());
- System.out.println("Should print 2: " + n.getLength());
- System.out.println("Should print 0: " + o.getLength());
- System.out.println("**Testing removeFirst**");
- L.removeFirst();
- System.out.println("Should print 2: " + L);
- L.removeFirst();
- System.out.println("Should print an new Line: " + L);
- System.out.println("Should an error message for an empty List: ");
- try {
- L.removeFirst();
- } catch(NoSuchElementException e) {
- System.out.println(e.getMessage());
- }
- //Tests for removeLast go here!
- System.out.println("\n**Testing removeLast**");
- n.removeLast();
- System.out.println("Should print 5: " + n);
- n.removeLast();
- System.out.println("Should print an new Line: " + n);
- System.out.println("Should an error message for an empty List: ");
- try {
- n.removeLast();
- } catch(NoSuchElementException e) {
- System.out.println(e.getMessage());
- }
- System.out.println("\n**Testing isEmpty**");
- List<Integer> L2 = new List<Integer>();
- System.out.println("Should print true: " + L2.isEmpty());
- //add another test for isEmpty() here!
- L2.addFirst(2);
- System.out.println("Should print false: " + L2.isEmpty());
- System.out.println("Testing doubles: ");
- List<Double> A = new List<Double>();
- List<Double> B = new List<Double>();
- List<Double> C = new List<Double>();
- System.out.println("should print nothing(empty list of List A: )" + A);
- double a = 1.1;
- double b = 2.2;
- double c = 3.3;
- double d = 4.4;
- double e = 5.5;
- double f = 6.6;
- double g = 7.7;
- A.addFirst(a);
- System.out.println("should print 1.1: " + A);
- A.addFirst(b);
- System.out.println("should print 2.2 then 1.1: " + A);
- System.out.println("**Testing addlast**");
- A.addLast(c);
- A.addLast(d);
- System.out.println("should print 2.2 1.1 3.3 4.4: " + A);
- System.out.println("**Testing getFirst**");
- System.out.println("should print 2.2 " + A.getFirst());
- System.out.println("**Testing getLast**");
- System.out.println("should print 4.4 " + A.getLast());
- System.out.println("**Testing getlength**");
- System.out.println("Should print 4: " + A.getLength());
- B.addLast(e);
- B.addLast(f);
- B.addLast(g);
- System.out.println("**Testing removeFirst**");
- B.removeFirst();
- System.out.println("Should print 6.6 7.7: " + B);
- B.removeFirst();
- System.out.println("Should print 7.7: " + B);
- C.addFirst(a);
- C.addFirst(c);
- C.addFirst(f);
- System.out.println("**Testing removeLast**");
- C.removeLast();
- System.out.println("Should print 6.6 3.3: " + C);
- C.removeLast();
- System.out.println("Should print 6.6: " + C);
- System.out.println("**Testing Strings**");
- List <String> s1 = new List<String>();
- List <String> s2 = new List<String>();
- List <String> s3 = new List<String>();
- String a1 = "a1";
- String b1 = "b1";
- String c1 = "c1";
- String d1 = "d1";
- String e1 = "e1";
- String f1 = "f1";
- String g1 = "g1";
- s1.addFirst(a1);
- System.out.println("should print a1: " + s1);
- s1.addFirst(b1);
- System.out.println("should print b1 then a1: " + s1);
- System.out.println("**Testing addlast**");
- s1.addLast(c1);
- s1.addLast(d1);
- System.out.println("should print b1 a1 c1 d1: " + s1);
- System.out.println("**Testing getFirst**");
- System.out.println("should print b1 " + s1.getFirst());
- System.out.println("**Testing getLast**");
- System.out.println("should print d1 " + s1.getLast());
- System.out.println("**Testing getlength**");
- System.out.println("Should print 4: " + s1.getLength());
- s2.addLast(e1);
- s2.addLast(f1);
- s2.addLast(g1);
- System.out.println("**Testing removeFirst**");
- s2.removeFirst();
- System.out.println("should print f1 g1 : " + s2);
- s2.removeFirst();
- System.out.println("Should print g1: " + s2);
- s3.addFirst(a1);
- s3.addFirst(c1);
- s3.addFirst(f1);
- System.out.println("**Testing removeLast**");
- s3.removeLast();
- System.out.println("Should print f1 c1: " + s3);
- s3.removeLast();
- System.out.println("Should print f1: " + s3);
- //////// ITERATOR TESTS
- System.out.println("**Testing Iterator Methods**");
- List <Integer> dl1 = new List<Integer>();
- dl1.addFirst(3);
- dl1.addFirst(2);
- dl1.addFirst(1);
- System.out.println("Should print 1 2 3: " + dl1);
- dl1.pointIterator();
- System.out.println("Testing pointIterator: ");
- System.out.println("Should print 1: " + dl1.getIterator());
- System.out.println("Testing advanceIterator & reverseIterator: ");
- dl1.advanceIterator();
- System.out.println("Should print 2: " + dl1.getIterator());
- dl1.advanceIterator();
- System.out.println("Should print 3: " + dl1.getIterator());
- dl1.reverseIterator();
- dl1.reverseIterator();
- System.out.println("Should print 1: " + dl1.getIterator());
- List<Integer> dl2 = new List<Integer>();
- System.out.println("Should throw getIterator exception: ");
- try {
- dl2.getIterator();
- } catch(NoSuchElementException ee) {
- System.out.println(ee.getMessage());
- }
- System.out.println("Testing removeIterator: ");
- dl1.advanceIterator();
- System.out.println("Should print 2: " + dl1.getIterator());
- System.out.println("Iterator pointing at 2. \n");
- System.out.println("Current list: " + dl1);
- dl1.removeIterator();
- System.out.println("Current list after "
- + "removeIterator called ( should be 1 3): " + dl1);
- dl1.pointIterator();
- dl1.removeIterator();
- System.out.println("Current list after "
- + "removeIterator called ( should be 3): " + dl1);
- System.out.println("Testing addIterator: ");
- List<Integer> dl3 = new List<Integer>();
- dl3.addLast(1);
- dl3.addLast(3);
- dl3.addLast(4);
- System.out.println("Should print 1 3 5: " + dl3);
- dl3.pointIterator(); // point at 1
- dl3.advanceIterator(); // point at 3
- dl3.advanceIterator();
- System.out.println("Get Iterator should be at 4: " + dl3.getIterator());
- dl3.addIterator(5); // adding at end of list
- System.out.println("ADDING AT END OF LIST");
- System.out.println("Should print 1 3 4 5: " + dl3);
- dl3.pointIterator(); // point at 1
- dl3.addIterator(2);
- System.out.println("ADDING AT FRONT OF LIST");
- System.out.println("Should print 1 2 3 4 5: " + dl3);
- dl3.advanceIterator(); // point at 2
- dl3.addIterator(22);
- System.out.println("Should print 1 2 22 3 4 5: " + dl3);
- Scheduler mySchedule = new Scheduler();
- mySchedule.app();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement