Skip to content

Add consistent edge-case preconditions to sorting and searching demos#15

Merged
Nullkernel merged 1 commit intomainfrom
codex/add-precondition-checks-for-algorithms
Apr 5, 2026
Merged

Add consistent edge-case preconditions to sorting and searching demos#15
Nullkernel merged 1 commit intomainfrom
codex/add-precondition-checks-for-algorithms

Conversation

@Nullkernel
Copy link
Copy Markdown
Owner

Motivation

  • Make interactive demos robust by validating user-provided sizes and avoiding common runtime errors.
  • Ensure consistent behavior across all sorting and searching examples for negative, zero-length, and null/empty-array inputs.
  • Document the intended edge-case semantics so maintainers and students understand how these examples behave on invalid or empty inputs.

Description

  • Added input-size validation to every interactive main in Sorting-algorithms and Searching-algorithms to reject negative sizes and early-return on 0 with the message Nothing to sort/search and a closed scanner.
  • Added algorithm-level guards (early-return or -1 for searches) for null/empty arrays such as if (arr == null || arr.length == 0) return; and adjusted helper methods accordingly.
  • Implemented the requested radixsort(int[] arr) guard and protected Quicksort_Hoare recursion entry with if (arr == null || arr.length == 0) return; and if (low >= high) return;.
  • Added a short comment block in each updated file describing the edge-case behavior for negative size, zero size, and null/empty arrays.

Testing

  • Ran the repository smoke compile script bash scripts/compile_smoke.sh.
  • Result: the compile smoke test passed and all Java files compiled successfully.

Codex Task

@Nullkernel Nullkernel merged commit 6dec9bc into main Apr 5, 2026
1 check passed
@Nullkernel Nullkernel deleted the codex/add-precondition-checks-for-algorithms branch April 6, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant