Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package assign1;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- System.out.println("Reading in from txt file.");
- //-------------------------------------------input from file *****
- MyList charLinkedList = new MyList(null);
- try {
- String filename = "list.txt";
- File file = new File(filename);
- Scanner in = new Scanner(file);
- while(in.hasNextLine()){
- String line = in.nextLine();
- char a = line.charAt(0);
- charLinkedList.insertAtPos(0, a);
- }
- in.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- System.out.println("File not found!");
- }
- System.out.println("Testing list generation and print function:");
- charLinkedList.print();
- System.out.println("\nTesting remove by index: 5 (f), and 0.");
- charLinkedList.remove(0); //-----------------------------------------------------remove head node
- charLinkedList.remove(5);//----------------------------------------------remove node from center of list
- charLinkedList.print();
- System.out.println("\nTesting remove by char: 'a'.");
- charLinkedList.remove('a');//-------------------------------------------------------test remove(char)
- charLinkedList.print();
- System.out.println("\nTesting removeAll char, a.");
- charLinkedList.insertAtPos(3, 'a');
- charLinkedList.insertAtPos(5, 'a');
- charLinkedList.insertAtPos(8, 'a');
- charLinkedList.insertAtPos(10, 'a');
- charLinkedList.print();
- charLinkedList.removeAll('a');//----------------------------------------------------test removeAll
- System.out.println("Position of 'a' = "+charLinkedList.find('a'));
- charLinkedList.print();
- System.out.println("\nTesting contains: search for 'a' then 'l'.");
- System.out.println(charLinkedList.contains('a'));//----------------------------------test contains fail
- System.out.println(charLinkedList.contains('l'));//----------------------------------test cointains success
- System.out.println("\nTesting set: indexes 0-2 to 'z', plus index 20 to 'z'.");
- charLinkedList.set(0,'z');//------------------------------------------------------test set success
- charLinkedList.set(1,'z');
- charLinkedList.set(2,'z');
- charLinkedList.print();
- charLinkedList.set(20,'z');//------------------------------------------------------test set fail
- System.out.println("\nTesting equals: list to nonequal list, then list to equal list.");
- System.out.println(charLinkedList.equals(charLinkedList.sublist(4, 8)));//--------------------test equals fail
- System.out.println(charLinkedList.equals(charLinkedList.sublist(0, charLinkedList.size())));//test equals success
- System.out.println("\nTesting pushFront and pushBack (utilize insertAfter and insertBefore methods).");
- System.out.println("Size before ="+charLinkedList.size());
- charLinkedList.pushFront('y');//---------------------------------------------------test pushfront
- charLinkedList.pushBack('y');//-----------------------------------------------------test pushback
- System.out.println("Size after ="+charLinkedList.size());
- charLinkedList.print();
- System.out.println("\nTesting popFront and popBack.");
- System.out.println("Size before ="+charLinkedList.size());
- charLinkedList.popFront();//----------------------------------------------------------test popfront
- charLinkedList.popBack();//-----------------------------------------------------------test pupback
- System.out.println("Size after ="+charLinkedList.size());
- charLinkedList.print();
- System.out.println("\nTesting swap: first and last value, then fail.");
- charLinkedList.swap(0, 11);//---------------------------------------------------------test swap success
- charLinkedList.print();
- charLinkedList.swap(0, 12);//-----------------------------------------------------------test swap fail
- System.out.println("\nTesting insertAtPos: front, rear, and out of index.");
- charLinkedList.insertAtPos(0, 'a'); //-----------------------------------------------test insertAtPos front
- charLinkedList.insertAtPos(charLinkedList.size()-1, 'b');//--------------------------test insertAtPos back
- charLinkedList.print();
- charLinkedList.insertAtPos(charLinkedList.size(), 'c'); //---------------------------test insertAtPos fail
- System.out.println("\nTesting sublist: sublist(3,6), and out of index.");
- MyList sublist = charLinkedList.sublist(3, 6);//----------------------------------------test sublist success
- sublist.print();
- MyList sublistf = charLinkedList.sublist(3, charLinkedList.size());//--------------------test sublist fails
- sublistf.print();
- System.out.println("\nTesting find: 'f' (4), and q (fail).");
- System.out.println("Position of 'f' = "+charLinkedList.find('f'));//------------------test find success
- System.out.println("Position of 'q' = "+charLinkedList.find('q'));//-------------------test find fail
- System.out.println("\nTesting toArray and MyList(char[],charArray)");
- MyList arraytolist = new MyList(charLinkedList.toArray(),charLinkedList.size());//---test arraytolist
- arraytolist.print();
- System.out.println("\nTesting reverse.");
- charLinkedList.reverse();//---------------------------------------------------------------test reverse
- charLinkedList.print();
- System.out.println("\nTesting toString.");
- System.out.println(charLinkedList.toString());//------------------------------------------test toString
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement