Skip to content

fix: handle division by zero in calculator#128

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

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

Conversation

@quantcode-agent
Copy link
Copy Markdown

Summary

  • Fixed the division-by-zero bug in src/calculator.ts by throwing an Error("Cannot divide by zero") when the divisor is 0
  • Added two new tests in test/calculator.test.ts covering normal division and the zero-divisor error case

Changes

  • src/calculator.ts: Added a guard if (b === 0) throw new Error("Cannot divide by zero") in the divide function
  • test/calculator.test.ts: Imported divide, removed the known-bug comment, added tests for normal division and division-by-zero

Test results

All 5 tests pass (bun test).

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