Skip to content

Fix LinkedList and Vector removal bugs; test untested data-structure branches - #12

Merged
diegourban merged 2 commits into
masterfrom
datastructure-fixes
Nov 6, 2026
Merged

diegourban merged 2 commits into
masterfrom
datastructure-fixes

Conversation

@diegourban

Copy link
Copy Markdown
Owner

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)

Before After
LinkedList.removeFromEnd() on a one-element list size became −1: decremented in removeFromStart() and again after the if/else the decrement moved into the else branch
Vector.remove(position) on a full vector (100 elements) ArrayIndexOutOfBoundsException: the loop read elements[i + 1] at the last index the loop stops at totalElements - 1

Both 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; invalid get; removeFromStart on an empty list; becoming empty from start and from end; remove first and last by position; toString of an empty list.
  • SetTest: duplicates are ignored; removing a missing word is ignored.
  • VectorTest: invalid add/get positions; contains with a missing element; remove from a full vector.
  • ElementTest (new): equality, equals(null) and toString.

Test files are in palantir format (as in #11), so merging this before #11 merges cleanly.

Test plan

  • ./mvnw verify: 591 tests, coverage floors met
  • CI, Codacy, Codecov green

After merging: I'll merge master into #11 so its Codecov patch check re-runs with these tests.

🤖 Generated with Claude Code

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>
@codacy-production

codacy-production Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 13 complexity · 0 duplication

Metric Results
Complexity 13
Duplication 0

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

⚠️ Resolve issues before merging

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 HIGH RISK

Suggestion: Use AssertJ's null assertion instead of invoking equals(null) directly.

See Issue in Codacy

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++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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-commenter

codecov-commenter commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.48%. Comparing base (ff88d77) to head (e3210a5).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…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>
@diegourban
diegourban merged commit 3d2320e into master Nov 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants