Repository navigation
datastructure.array: generic DynamicArray<T> - #18
diegourban wants to merge 3 commits into
Conversation
The class is documented (growth policy, contract, exceptions) but every method throws UnsupportedOperationException, to be implemented by hand. - IntDynamicArrayTest: 11 examples, incl. doubling when full and halving at a quarter full, never below the initial capacity of 10 - IntDynamicArrayPropertyTest: jqwik model-based check that random add/insert/set/remove sequences keep it identical to an ArrayList The 12 new tests fail until the implementation lands. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 53 |
| Duplication | 2 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
popBack nulled fixedArray[size] before size -= 1, so on a full array it wrote one past the end (ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 10, found by DynamicArrayPropertyTest in CI), and on other arrays it cleared the empty slot after the last value instead of releasing the removed one. Decrement first, then clear. New example test popBackFromAFullArray failed before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18 +/- ##
============================================
+ Coverage 99.65% 99.83% +0.18%
- Complexity 294 314 +20
============================================
Files 24 25 +1
Lines 574 611 +37
Branches 101 103 +2
============================================
+ Hits 572 610 +38
+ Partials 2 1 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
👀 Worth a closer look
The growth logic can overflow at very large capacities, causing an append to fail with an invalid array size even when growth may still be possible. This warrants review before relying on the implementation at extreme sizes.
One recommended shrinking-boundary test remains missing; no uncovered complex files were reported.
Test suggestions
- Appending values preserves order and supports growth beyond the initial capacity.
- Appending to an exactly full array and then removing works correctly.
- Getting and setting valid indexes works for generic values, including null.
- Invalid positive and negative indexes are rejected for get, set, and pop.
- Popping from an empty array is rejected.
- popBack removes and returns no value while pop(index) returns the removed value and shifts later elements.
- Removing enough elements triggers shrinking while preserving remaining values.
- Repeated shrinking never reduces capacity below the initial capacity.
- Arbitrary operation sequences match ArrayList behavior.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Repeated shrinking never reduces capacity below the initial capacity.
TIP Add review instructions in .codacy/instructions/review.md, or an AGENTS.md, so the reviewer knows your conventions.
TIP How was this review? Give us feedback
| */ | ||
| public void append(final T value) { | ||
| if (this.size == this.capacity) { | ||
| this.resize(this.capacity * 2); |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Capacity growth is not overflow-safe: doubling a sufficiently large capacity can wrap to a negative value and cause NegativeArraySizeException on the next append. Guard the calculation, cap it at the maximum supported array size, and report exhaustion when no further growth is possible.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
A growable, generic list backed by an array:
DynamicArray<T>indatastructure.array. It started as anint-only stub (IntDynamicArray); the implementation is hand-written.API
append,get,set,size,popBack, andpop(index)(returns the removed value). Invalid indexes throwIndexOutOfBoundsException.Growth policy
pop(index).The backing store is
(T[]) new Object[n], because Java can't create an array of a type parameter. The cast is safe because onlyTvalues are ever stored.popBackclears the removed slot so the object can be garbage-collected.Tests
DynamicArrayTest: 12 examples, including aString/nullcase and popping from an exactly full array.DynamicArrayPropertyTest: jqwik model-based check. Random sequences of append, set, popBack and pop (up to 200 operations) must leave the array identical to ajava.util.ArrayListafter every step. In CI it found apopBackbug on a full array, now fixed.Later
Replace the old
datastructure.vector.VectorwithDynamicArray<T>.🤖 Generated with Claude Code