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 testBasicInsert() {
listWithNull.insert(0, Integer.valueOf(5));
listCustomCapacity.insert(0, 100);
assertEquals("should insert 5 to the list", 5, listWithNull.data[0]);
assertEquals("should increment size", 11, listWithNull.size);
assertEquals("check that if the capacity is updated", 20, listWithNull.data.length);
assertEquals("should insert 5 to the list", 100, listCustomCapacity.data[0]);
assertEquals("should increment size", 1, listCustomCapacity.size);
assertEquals("capacity of the list should not change when insert one elem", 3, listCustomCapacity.data.length);
}
How do I insert a out of bounds index with unit testing?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started