← 返回首页
fix: correct misleading error message in MidpointIntegration by shaked-shlomo · Pull Request #1902 · TheAlgorithms/JavaScript · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

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

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 requested a review from appgurueu as a code owner June 1, 2026 13:30
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.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Footer

© 2026 GitHub, Inc.