Repository navigation
Fix LinkedList and Vector removal bugs; test untested data-structure branches - #12
Conversation
Adds tests for the untested branches of LinkedList, Set, Vector and Element. Two of them exposed bugs: - LinkedList.removeFromEnd on a one-element list decremented the size twice (once in removeFromStart, once after the if/else), leaving -1. The decrement now only happens in the branch that doesn't delegate. - Vector.remove read elements[i + 1] up to the last element, so removing from a full vector threw ArrayIndexOutOfBoundsException. The loop now stops one before the end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 13 |
| Duplication | 0 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
The Vector removal implementation still needs bounds validation before shifting and decrementing the element count; an invalid position can corrupt the vector state or trigger an array error. No acceptance-criterion gaps or uncovered complex files were reported.
Test suggestions
- Remove the only element from the end of a LinkedList and verify size zero and empty output.
- Remove an element from a full Vector and verify size and shifted contents.
- Add to an empty LinkedList and add at the end by position.
- Reject invalid LinkedList get positions.
- Reject removing from the start of an empty LinkedList.
- Remove the first and last LinkedList elements by position.
- Verify empty LinkedList string representation.
- Ignore duplicate Set entries.
- Ignore removal of a missing Set entry.
- Reject invalid Vector add and get positions.
- Verify Vector does not contain a missing element.
- Verify Element equality, null inequality, and string representation.
Make this review better
TIP Add a ticket key to the branch or title so the reviewer can check the PR against it. Or tell us which ticket tracker you use here.
TIP Add Codacy review.md instructions or an AGENTS.md so the reviewer knows your conventions.
TIP How was this review? Give us feedback
|
|
||
| @Test | ||
| void shouldNotEqualNull() { | ||
| assertThat(new Element("diego").equals(null)).isFalse(); |
There was a problem hiding this comment.
🔴 HIGH RISK
Suggestion: Use AssertJ's null assertion instead of invoking equals(null) directly.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
|
|
||
| public void remove(final int position) { | ||
| for(int i = position; i < this.totalElements; i++) { | ||
| for(int i = position; i < this.totalElements - 1; i++) { |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Add a bounds check before shifting and decrementing the element count, rejecting positions that are negative or not occupied.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12 +/- ##
============================================
+ Coverage 94.00% 99.48% +5.47%
- Complexity 255 278 +23
============================================
Files 24 24
Lines 584 584
Branches 94 94
============================================
+ Hits 549 581 +32
+ Misses 16 0 -16
+ Partials 19 3 -16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ctly Codacy/PMD EqualsNull flagged the direct equals(null) call in the test. assertThat(element).isNotEqualTo(null) still invokes Element.equals(null), so the null branch stays covered (JaCoCo: 2/2 branches). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Split out of #11: Codecov flagged lines there that the reformat touched and no test ran. Writing tests for those branches exposed two bugs.
Bugs fixed (one line each)
LinkedList.removeFromEnd()on a one-element listremoveFromStart()and again after theif/elseelsebranchVector.remove(position)on a full vector (100 elements)ArrayIndexOutOfBoundsException: the loop readelements[i + 1]at the last indextotalElements - 1Both failing tests were written first (red), then fixed (green).
New tests (17)
LinkedListTest: add at a position in an empty list and at the end; invalidget;removeFromStarton an empty list; becoming empty from start and from end; remove first and last by position;toStringof an empty list.SetTest: duplicates are ignored; removing a missing word is ignored.VectorTest: invalidadd/getpositions;containswith a missing element; remove from a full vector.ElementTest(new): equality,equals(null)andtoString.Test files are in palantir format (as in #11), so merging this before #11 merges cleanly.
Test plan
./mvnw verify: 591 tests, coverage floors metAfter merging: I'll merge
masterinto #11 so its Codecov patch check re-runs with these tests.🤖 Generated with Claude Code