diff --git a/src/IListTest.java b/src/IListTest.java new file mode 100644 index 0000000..8d87919 --- /dev/null +++ b/src/IListTest.java @@ -0,0 +1,75 @@ + +public class IListTest { + public static void main(String[] args) { + System.out.println("The testing is starting..."); + + IList list = new List(); + + /*************************************** + * Testing to add elements to the list. + ***************************************/ + list.addAt(0, "1"); // 1 + list.addAt(1, "2"); // 1, 2 + list.addAt(0, "3"); // 3, 1, 2 + list.addAt(1, "4"); // 3, 4, 1, 2 + + System.out.println("Expected output: 3, 4, 1, 2"); + for (int i = 0; i < list.size(); ++i) { + System.out.println(list.getAllElementsAsStrings()[i]); + } + + /*************************************** + * Testing to get the size of the list. + ***************************************/ + System.out.println("Expected output: Size: 4"); + System.out.println("Size: " + list.size()); + + /*************************************** + * Testing to remove two elements and a third element that doesn't exist. + ***************************************/ + System.out.println("Expected output: true, true, false"); + System.out.println(list.removeAt(0)); // 4, 1, 2 + System.out.println(list.removeAt(2)); // 4, 1 + System.out.println(list.removeAt(2)); // 4, 1 + + /*************************************** + * Print out the list. + ***************************************/ + System.out.println("Expected output: 4, 1"); + for (int i = 0; i < list.size(); ++i) { + System.out.println(list.getAllElementsAsStrings()[i]); + } + + /*************************************** + * Try to find an item that exists, and one that doesn't. + ***************************************/ + System.out.println("Expected output: 1, -1"); + System.out.println(list.find("1")); + System.out.println(list.find("2")); + + /*************************************** + * Testing appending a list to a list. + ***************************************/ + IList newList = new List(); + newList.addAt(5, "5"); + newList.addAt(5, "7"); + newList.addAt(5, "11"); + + list.append(newList); + + System.out.println("Expected output: 4, 1, 5, 7, 11"); + for (int i = 0; i < list.size(); ++i) { + System.out.println(list.getAllElementsAsStrings()[i]); + } + + /*************************************** + * Testing to clear the list and remove an element from an empty list. + ***************************************/ + System.out.println("Expected output: Size: 0, false"); + list.clear(); + System.out.println("Size: " + list.size()); + System.out.println(list.removeAt(0)); + + System.out.println("The testing has ended..."); + } +}