Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.7 kB
1
Indexable
Never
class CustomArrayListTest {
	public CustomArrayList emptyList, list1, list2, list3;

	@BeforeEach
	public void run() {
		emptyList = new CustomArrayList();
		list1 = new CustomArrayList();
		list1.add(10);
		list1.add(70);
		list1.add(20);
		list1.add(90);
		//list1 = [10, 70, 20, 90]

		list2 = new CustomArrayList();
		list2.add(-5);
		list2.add(5);
		list2.add(2);
		list2.add(1);
		list2.add(-55);
		list2.add(-5);
		list2.add(0);
		list2.add(0);
		list2.add(8);
		list2.add(0);
		//list2 = [-5, 5, 2, 1, -55, -5, 0, 0, 8, 0]

		list3 = new CustomArrayList();
		list3.add(-6);
		//list3 = [-6]
	}

	@Test
	void testIsEmpty() {
		assertTrue(emptyList.isEmpty());
		assertFalse(list1.isEmpty());
		assertFalse(list2.isEmpty());
		assertFalse(list3.isEmpty());
	}

	@Test
	void testToString() {
		assertEquals("[]",emptyList.toString());
		assertEquals("[10, 70, 20, 90]",list1.toString());
		assertEquals("[-5, 5, 2, 1, -55, -5, 0, 0, 8, 0]",list2.toString());
		assertEquals("[-6]",list3.toString());

	}

	@Test
	void testGrow() {
		assertEquals(4, list1.currentSize());
		assertEquals(10, list1.currentCapacity());
		assertFalse(list1.isFull());

		list1.grow();
		assertEquals("[10, 70, 20, 90]", list1.toString()); //ensure values are correct after grow() executes
		assertEquals(4, list1.currentSize());
		assertEquals(15, list1.currentCapacity());
		assertFalse(list1.isFull());

		list1.grow();
		assertEquals("[10, 70, 20, 90]", list1.toString()); //ensure values are correct after grow() executes

		assertEquals(4, list1.currentSize());
		assertEquals(20, list1.currentCapacity());
		assertFalse(list1.isFull());
	}