/** To test if inserting at the first spot works */ @Test public void testInsertFirst() { // insert a letter at the first node filledTest.insertFirst("X"); twoTest.insertFirst("Y"); oneTest.insertFirst("Z"); emptyTest.insertFirst("A"); // the first letter should be whatever I've inserted (see above) assertEquals("X", filledTest.getFirst()); assertEquals("Y", twoTest.getFirst()); assertEquals("Z", oneTest.getFirst()); assertEquals("A", emptyTest.getFirst()); }
/** To create a generic list, and subtly test if insertFirst function works */ @Before public void createList() { // create a string called "testString" backwards String string = "gnirtStset"; // go through a for loop for (int i = 0; i < string.length(); i++) { // create a new node with each letter (starting at the end, which is why I had to make it // backwards before) filledTest.insertFirst(String.valueOf(string.charAt(i))); } // create a string called "te" backwards String two = "et"; // go through a for loop for (int j = 0; j < two.length(); j++) { // create a new node with each letter (starting at the end, which is why I had to make it // backwards before) twoTest.insertFirst(String.valueOf(two.charAt(j))); } // create a new node with t oneTest.insertFirst("t"); }