Question: import static org.junit.Assert.*; import org.junit.*; public class MyArrayListPublicTester { static final int DEFAULT_CAPACITY = 5; static final int MY_CAPACITY = 3; Object[] arr = new
import static org.junit.Assert.*;
import org.junit.*;
public class MyArrayListPublicTester {
static final int DEFAULT_CAPACITY = 5;
static final int MY_CAPACITY = 3;
Object[] arr = new Object[10];
Integer[] arrInts = { 1, 2, 3 };
private MyArrayList listEmpty, listDefaultCap, listCustomCapacity, listWithNull, listWithInt;
public void setUp() throws Exception {
listEmpty = new MyArrayList();
listDefaultCap = new MyArrayList(DEFAULT_CAPACITY);
listCustomCapacity = new MyArrayList(MY_CAPACITY);
listWithNull = new MyArrayList(arr);
listWithInt = new MyArrayList
}
public void testBasicAppendEmpty() {
listCustomCapacity.append(3);
assertEquals("Check that append increments size", 1, listCustomCapacity.size);
assertEquals("Check that capacity is unchanged", 3, listCustomCapacity.data.length);
assertEquals("check the correct element", 3, listCustomCapacity.data[0]);
}
Test if an element is correctly inserted at the end of the ArrayList, while preserving existing elements. Size and capacity should be updated to reflect the change to the ArrayList where applicable.
How do I append to a full ArrayList?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
