Skip to content

fix: handle division by zero in calculator#151

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

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

Conversation

@quantcode-agent
Copy link
Copy Markdown

Summary

  • Added a guard clause in src/calculator.ts divide() function that throws an Error("Cannot divide by zero") when the divisor is 0, preventing Infinity/NaN results.
  • Added test cases in test/calculator.test.ts verifying both normal division and the zero-divisor error.

Assumptions

  • The appropriate behavior for division by zero is to throw an error rather than returning a special value.
  • All 5 tests pass (verified with bun test).

Add guard clause to divide() that throws 'Cannot divide by zero' error
when divisor is 0. Add corresponding test cases.
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