Skip to content

fix: handle division by zero in calculator#136

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

fix: handle division by zero in calculator#136
quantcode-agent[bot] wants to merge 1 commit intomainfrom
quantcode/job-job-d28c9eb2

Conversation

@quantcode-agent
Copy link
Copy Markdown

Summary

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

Changes

  • src/calculator.ts: Added guard clause at the top of divide() to check for zero divisor
  • test/calculator.test.ts: Added test for successful division and test verifying the error is thrown on divide-by-zero

Testing

All 5 tests pass (bun test).

- Add guard clause in divide() to throw Error when divisor is zero
- Add tests for normal division and divide-by-zero error case
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