Skip to content

fix: handle division by zero in calculator#131

Open
stooit wants to merge 1 commit intomainfrom
quantcode/job-local-simple-1777520448
Open

fix: handle division by zero in calculator#131
stooit wants to merge 1 commit intomainfrom
quantcode/job-local-simple-1777520448

Conversation

@stooit
Copy link
Copy Markdown
Contributor

@stooit stooit commented Apr 30, 2026

Summary

  • Fixes division-by-zero bug in src/calculator.ts by adding a guard that throws an Error("Division by zero") when the divisor is 0
  • Adds test coverage for both normal division and the division-by-zero error case

Changes

  • src/calculator.ts: Added zero-check in the divide function before performing division
  • test/calculator.test.ts: Added tests for divide — verifying correct results and that dividing by zero throws

Assumptions

  • Throwing an Error is the appropriate behaviour (rather than returning Infinity or NaN)
  • The error message "Division by zero" is sufficient for consumers of this function

Testing

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.

1 participant