diff --git a/tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java b/tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java index ad8779083665ae7dd04d26a0cf8551b875dd088d..5ac09fb534918de3868660988e9530222fa99f08 100644 --- a/tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java +++ b/tests/edu/caltech/cs2/datastructures/ArrayDequeTests.java @@ -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() { diff --git a/tests/edu/caltech/cs2/project03/Project03TestOrdering.java b/tests/edu/caltech/cs2/project03/Project03TestOrdering.java index 1cbf6315694262bb37c4ffc2f1af112ba7f81163..86a4c349d98e8afab90c55942b0bdb8b552187f1 100644 --- a/tests/edu/caltech/cs2/project03/Project03TestOrdering.java +++ b/tests/edu/caltech/cs2/project03/Project03TestOrdering.java @@ -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; }