Commit 730392cc authored by Ethan Ordentlich's avatar Ethan Ordentlich
Browse files

Fix test for array capacity

parent 2860e23a
1 merge request!2Small revisions
Showing with 8 additions and 4 deletions
+8 -4
...@@ -129,14 +129,18 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests { ...@@ -129,14 +129,18 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
// ARRAYDEQUE TESTS --------------------------------------------------- // ARRAYDEQUE TESTS ---------------------------------------------------
@Order(implSpecificTestLevel) @Order(implSpecificTestLevel)
@DisplayName("The default capacity of the array is 10")
@Test @Test
public void testArrayDequeDefaultInitialCapacity() throws IllegalAccessException { public void testArrayDequeDefaultInitialCapacity() throws IllegalAccessException {
ArrayDeque<Integer> impl = new ArrayDeque<>(); ArrayDeque<Integer> impl = new ArrayDeque<>();
// Reflect and get the backing array // Reflect and get the backing array
Field arr = Reflection.getFieldByType(ArrayDeque.class, int[].class); // It's actually an Object[] since that's how it (should!) be initialized internally
// Casting it doesn't change the type of the field.
// It's fine since there should only be one array.
Field arr = Reflection.getFieldByType(ArrayDeque.class, Object[].class);
arr.setAccessible(true); arr.setAccessible(true);
int[] backingArray = (int[]) arr.get(impl); Integer[] backingArray = (Integer[]) arr.get(impl);
assertEquals(10, backingArray.length, "Default initial capacity is not 10"); assertEquals(10, backingArray.length, "Default initial capacity is not 10");
} }
...@@ -147,7 +151,7 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests { ...@@ -147,7 +151,7 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
public void testThatArrayDequeEnqueueAlwaysSucceeds() { public void testThatArrayDequeEnqueueAlwaysSucceeds() {
ArrayDeque<Integer> impl = new ArrayDeque<>(); ArrayDeque<Integer> impl = new ArrayDeque<>();
for (int i = 0; i < 100; i ++) { for (int i = 0; i < 100; i ++) {
assertTrue(impl.enqueue(i), "enqueue should always succeed for ArrayDeque"); assertTrue(impl.enqueue(i), "enqueue() should always succeed for ArrayDeque");
} }
} }
...@@ -157,7 +161,7 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests { ...@@ -157,7 +161,7 @@ public class ArrayDequeTests implements IDequeTests, IStackTests, IQueueTests {
public void testThatArrayDequePushAlwaysSucceeds() { public void testThatArrayDequePushAlwaysSucceeds() {
ArrayDeque<Integer> impl = new ArrayDeque<>(); ArrayDeque<Integer> impl = new ArrayDeque<>();
for (int i = 0; i < 100; i ++) { for (int i = 0; i < 100; i ++) {
assertTrue(impl.push(i), "push should always succeed for ArrayDeque"); assertTrue(impl.push(i), "push() should always succeed for ArrayDeque");
} }
} }
......
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