Skip to content

fix: handle division-by-zero bug in calculator#138

Open
quantcode-agent[bot] wants to merge 1 commit intomainfrom
quantcode/job-job-27edaeff
Open

fix: handle division-by-zero bug in calculator#138
quantcode-agent[bot] wants to merge 1 commit intomainfrom
quantcode/job-job-27edaeff

Conversation

@quantcode-agent
Copy link
Copy Markdown

Summary

  • Fixes the division-by-zero bug in src/calculator.ts where divide(x, 0) would return Infinity instead of raising an error
  • The divide() function now throws Error("Cannot divide by zero") when the divisor is zero
  • Added test cases for normal division and the divide-by-zero error scenario

Assumptions

  • The appropriate behavior for division by zero is to throw an Error rather than returning a special value
  • The error message "Cannot divide by zero" is descriptive enough for consumers of this function

Testing

All 5 tests pass (bun test).

- Add guard clause in divide() to throw Error when divisor is zero
- Add test cases for normal division and divide-by-zero scenario
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.

0 participants