Skip to content

fix: correct misleading error message in MidpointIntegration#1902

Open
shaked-shlomo wants to merge 1 commit into
TheAlgorithms:masterfrom
shaked-shlomo:fix/midpoint-integration-error-message
Open

fix: correct misleading error message in MidpointIntegration#1902
shaked-shlomo wants to merge 1 commit into
TheAlgorithms:masterfrom
shaked-shlomo:fix/midpoint-integration-error-message

Conversation

@shaked-shlomo
Copy link
Copy Markdown

Description

In Maths/MidpointIntegration.js the guard rejects non-positive N:

if (N <= 0) {
  throw Error('N has to be >= 2')
} // check if N > 0

The thrown message says 'N has to be >= 2', but:

  • the check only rejects N <= 0,
  • the inline comment says check if N > 0, and
  • the function docstring states "N must be > 0".

N = 1 is a valid number of subintervals for the midpoint rule, so the >= 2 message is incorrect and misleading. This changes it to 'N has to be > 0' to match the actual validation and the documentation.

(Note: the analogous >= 2 message in SimpsonIntegration.js is correct there, since Simpson's rule additionally requires an even N, so the minimum is 2 — left unchanged.)

Checklist

  • Fix is a single, self-contained change.
  • No existing test asserts the old message.
  • No behavior change beyond the error string.

🤖 Generated with Claude Code

The validation throws when N <= 0, and the docstring states 'N must be > 0',
but the message claimed 'N has to be >= 2'. N = 1 is valid for the midpoint
rule, so the message now matches the actual check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@shaked-shlomo shaked-shlomo requested a review from appgurueu as a code owner June 1, 2026 13:30
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.91%. Comparing base (5c39e87) to head (2e1ba82).

Files with missing lines Patch % Lines
Maths/MidpointIntegration.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1902   +/-   ##
=======================================
  Coverage   85.91%   85.91%           
=======================================
  Files         379      379           
  Lines       19778    19778           
  Branches     3016     3016           
=======================================
  Hits        16993    16993           
  Misses       2785     2785           

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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