Here is the code we wrote today. First the test cases:
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class TestOurList {
private OurArrayList< String> list;
@Before
public void setup() {
list = new OurArrayList< String>();
}
@Test
public void testRemove() {
//remove returns null if list is empty
assertEquals(null, list.remove());
//if it's not empty, return an arbitrary element which isn't in the list anymore
list.add("A");
list.add("B");
list.add("C");
assertEquals(3, list.size());
String s = list.remove();
assertEquals(2, list.size());
assertEquals(false, list.contains(s));
}
}
Here is what we added to OurArrayList:
public T remove() {
//return arbitrary element (null if List is empty)
if(num == 0)
return null;
num--;
T retVal = vals[num];
return retVal;
}
}