// Allison Obourn // CSE 143 - Lecture 14 // A partial set of unit tests for the LinkedIntList class. // You will need to download and set up JUnit to run this code // directions for how to do this are in the slides import org.junit.Assert; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; public class LinkedIntListTest { // cases we should have tests for: // index 0 // negative index // index at the size // list is empty, when full // index > size // between 0 and size // tests adding to an empty list @Test public void addWhenEmptyTest() { IntList list = new LinkedIntList(); list.add(0, 0); Assert.assertEquals("adding to an empty list", list.get(0), 0); } // tests that adding at a negative index throws an IllegalArgumentException @Test (expected = IllegalArgumentException.class) public void addAtNegativeIndexTest() { IntList list = new LinkedIntList(); list.add(-1, 0); } // tests adding somewhere in the middle of a list @Test public void addToMiddleTest() { IntList list = new LinkedIntList(); list.add(1); list.add(2); list.add(1, 3); Assert.assertEquals("adding to the middle of a list, index 0", list.get(0), 1); Assert.assertEquals("adding to the middle of a list, index 1", list.get(1), 3); Assert.assertEquals("adding to the middle of a list, index 2", list.get(2), 2); } }