Commit 2860e23a authored by Ethan Ordentlich's avatar Ethan Ordentlich
Browse files

Fix #4

Add test for array initial capacity
parent 290faf92
1 merge request!2Small revisions
Pipeline #43060 canceled with stage
Showing with 43 additions and 5 deletions
+43 -5
......@@ -17,7 +17,7 @@ import java.util.stream.Stream;
import static edu.caltech.cs2.project03.Project03TestOrdering.*;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@Tag("C")
......@@ -126,6 +126,40 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
Inspection.assertConstructorHygiene(ARRAY_DEQUE_SOURCE);
}
// ARRAYDEQUE TESTS ---------------------------------------------------
@Order(implSpecificTestLevel)
@Test
public void testArrayDequeDefaultInitialCapacity() throws IllegalAccessException {
ArrayDeque<Integer> impl = new ArrayDeque<>();
// Reflect and get the backing array
Field arr = Reflection.getFieldByType(ArrayDeque.class, int[].class);
arr.setAccessible(true);
int[] backingArray = (int[]) arr.get(impl);
assertEquals(10, backingArray.length, "Default initial capacity is not 10");
}
@Order(implSpecificTestLevel)
@DisplayName("enqueue should always succeed")
@Test
public void testThatArrayDequeEnqueueAlwaysSucceeds() {
ArrayDeque<Integer> impl = new ArrayDeque<>();
for (int i = 0; i < 100; i ++) {
assertTrue(impl.enqueue(i), "enqueue should always succeed for ArrayDeque");
}
}
@Order(implSpecificTestLevel)
@DisplayName("push should always succeed")
@Test
public void testThatArrayDequePushAlwaysSucceeds() {
ArrayDeque<Integer> impl = new ArrayDeque<>();
for (int i = 0; i < 100; i ++) {
assertTrue(impl.push(i), "push should always succeed for ArrayDeque");
}
}
// TOSTRING TESTS ---------------------------------------------------
......@@ -174,7 +208,7 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
}
@Order(complexityTestLevel)
@DisplayName("addBack() and removeBack() take linear time")
@DisplayName("addBack() and removeBack() take constant time")
@Timeout(value = 20, unit = SECONDS)
@Test
public void testBackDequeOperationComplexity() {
......
......@@ -5,6 +5,7 @@ public final class Project03TestOrdering {
throw new InstantiationError("Class is only for storing constant variables");
}
// Tests related to class structure
public static final int classSpecificTestLevel = 0;
public static final int collectionTestLevel = 1;
......@@ -14,8 +15,11 @@ public final class Project03TestOrdering {
public static final int fixedSizeQueueLevel = 3;
public static final int toStringTestLevel = 4;
public static final int complexityTestLevel = 5;
// Tests related to the particular implementation
public static final int implSpecificTestLevel = 4;
public static final int guitarStringTestLevel = 6;
public static final int toStringTestLevel = 5;
public static final int complexityTestLevel = 6;
public static final int guitarStringTestLevel = 7;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment