Divide numbers #4
Labels
No labels
aira:blocked
aira:cancelled
aira:ci
aira:done
aira:implementing
aira:merging
aira:plan-review
aira:planning
aira:qa
aira:queued
aira:ready
aira:review
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
lab/web-calculator#4
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add division with safe handling of division by zero.
Requirements
op=dividereturnsa / b.400 {"error": "division by zero"}; neverInfinityorNaN.÷button. Pressing9,÷,3,=shows3; dividing by zero showsErroron the display, andCclears it.Acceptance criteria
/api/calculate?a=9&b=3&op=dividereturns{"result":3}./api/calculate?a=1&b=4&op=dividereturns{"result":0.25}./api/calculate?a=1&b=0&op=dividereturns 400{"error":"division by zero"}.ErrorandCresets the display.Aira · queued
Aira picked up this task. Branch
aira/4-divide-numbers.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/4-divide-numbers.T3 thread:
mcp:launch:16a47c7b2214ac15b6b8885abb1780034c3ad0506ce123413a2016f8621a31c9Aira · Plan (round 1) at
3ce80ecbAdded docs/plans/issue-4.md (goal, AC1–4, design, files, test plan, risks), committed on aira/4-divide-numbers, pushed to origin.
docs/plans/issue-4.md
Issue #4: Divide numbers
Goal
Add division alongside add, subtract, and multiply: a pure
dividefunction with explicit division-by-zero handling (neverInfinityorNaN),op=divideonGET /api/calculate, and a÷button on the calculator UI following the same operand / equals flow as the other operations. Preserve existing operations,/health,/static serving, and standard invalid-input error handling.Acceptance criteria
/api/calculate?a=9&b=3&op=dividereturns{"result":3}./api/calculate?a=1&b=4&op=dividereturns{"result":0.25}./api/calculate?a=1&b=0&op=dividereturns HTTP 400{"error":"division by zero"}.÷) button; keypad flow9→÷→3→=shows3; dividing by zero showsErroron the display, andCresets the display to0.Design
Calculation module (
lib/calculator.js)divide(a, b)— pure numeric division (a / b) for non-zerob.calculate(rawA, rawB, op):op === 'divide'alongside existing operations.parseOperand(unchanged).op === 'divide'and parsedb === 0, throwCalculatorError('division by zero')before calling/so the API never returnsInfinityorNaN.divide(a, b)and keep the existing finite-result guard (Result out of range) for pathological float cases unrelated to divide-by-zero.opwithCalculatorError('Unknown operation')(unchanged).dividealongside existing exports.HTTP layer (
server.js)/api/calculatealready mapsCalculatorErrorto400 {"error": err.message}.400 {"error":"division by zero"}once the module throws the dedicated message.UI (
public/index.html)÷button (Unicode division sign U+00F7) on the keypad grid alongside+,−, and×.else if (key === '÷') commitOperand('divide');using the existingpendingOp/evaluatepattern.=, displayString(body.result)as today (e.g.0.25for1 ÷ 4 =).!res.ok), set the display to the literalError(acceptance criterion 4), not the JSONerrorstring — so divide-by-zero showsErrorwhile the API still returns"division by zero".Ccontinues to callreset()and restore display0(including after an error state).Test layout
test/calculator.test.jsdivide,calculatewithop=divide, division by zero message, regressions for other ops.test/server.test.jstest/ui.test.js÷button presence,commitOperand('divide'), and that failed evaluate showsError(static HTML/JS assertions).Files to change
lib/calculator.jsdivide, extendcalculatedispatch, explicitb === 0check for divide.server.jspublic/index.html÷button,commitOperand('divide'), displayErroron API failure.test/calculator.test.jstest/server.test.jstest/ui.test.jsErrordisplay behaviour.docs/plans/issue-4.mdNo changes to
package.json, CI workflows, or dependencies (Node built-ins only).Test plan
Unit (
test/calculator.test.js)divide(9, 3) === 3;calculate('9', '3', 'divide') === 3.divide(1, 4) === 0.25;calculate('1', '4', 'divide') === 0.25.calculate('1', '0', 'divide')throwsCalculatorErrorwith messagedivision by zero.divide(1, 0)or direct zero divisor path does not returnInfinity/NaNviacalculate.calculatetests unchanged; unknownopstill throwsCalculatorError.dividemirror other operations.HTTP (
test/server.test.js)a=9&b=3&op=divide{ result: 3 }a=1&b=4&op=divide{ result: 0.25 }a=1&b=0&op=divide{ error: 'division by zero' }UI / page (
test/ui.test.js)÷; HTML includesdata-key="÷".commitOperand('divide')and/api/calculatewithop: pendingOp.Error(e.g. matchsetDisplay('Error')or equivalent in the!res.okbranch);reset/Cclears to0.Pre-push
npm testlocally; all tests green beforegit push origin aira/4-divide-numbers.Risks
a / bwhenb === 0yieldsInfinity/NaNcalculateforop === 'divide'before division; unit and HTTP tests for AC3.errortext instead ofErroron the displayevaluatefailure branch per AC4; assert inui.test.js.÷(U+00F7) with/indata-key/ handlers÷.Error=targets usable.0.25resultas JSON number; display viaString(body.result)./healthor/Attachment: plan-4-r1.md
Aira · plan review
Plan pushed at
3ce80ecb; independent Dodik plan review started.Aira · dodik-plan PASS on
3ce80ecbThe plan at
3ce80ecmaps each task requirement to a numbered, testable acceptance criterion and matches the current code. Division belongs in lib/calculator.js with an explicit b === 0 check before the division operator, because the existing finite-result guard would otherwise turn Infinity and NaN into Result out of range. server.js already maps CalculatorError to 400 with err.message, so the API contract needs no HTTP change. The page must add a ÷ button wired through commitOperand('divide') and show the literal Error on a failed response; C already resets the display to 0. Unit, HTTP, and static UI tests cover the success cases, division by zero, invalid operands, and the existing add, subtract, and multiply behavior. npm test currently passes 32 tests, and the plan stays inside the calculator module, the page, and tests.Checks performed
Attachment: dodik-plan-3ce80ecb.json
Aira · implementing
Plan approved by Dodik at
3ce80ecb. Implementation started.Aira · ci
Ready for review at
7281c010(PR #8). Waiting for CI.Implemented divide in lib/calculator.js (division by zero → CalculatorError), ÷ button and Error display in public/index.html, unit/HTTP/UI tests for AC1–4; npm test 41/41 pass; pushed aira/4-divide-numbers.
Aira · CI passed on
7281c010Aira · review
CI is green on
7281c010. Independent Dodik and code review started.Aira · dodik PASS on
7281c010Division with an explicit division-by-zero error is implemented as specified in docs/plans/issue-4.md. Module, API, and page checks match every acceptance criterion, the full suite passes with no skipped or weakened tests, and the diff contains only the planned files.
Checks performed
7281c010cfwith origin/main and docs/plans/issue-4.md; only calculator, index.html, three test files, and the plan changedAttachment: dodik-7281c010.json
Aira · reviewer PASS on
7281c010The division feature is implemented correctly:
calculaterejects zero divisors withdivision by zerobefore calling/, successful cases match the acceptance criteria, the UI adds÷and showsErroron failed API responses per AC4, and the full test suite (41 tests) passes with no regressions to existing operations,/health, or static serving.Checks performed
7281c010cfAttachment: reviewer-7281c010.json
Aira · qa
Dodik and the reviewer passed on
7281c010. Preview deployed at http://127.0.0.1:36163; QA started.Aira · qa PASS on
7281c010Commit
7281c010cfserves GET /health with that sha. GET /api/calculate?a=9&b=3&op=divide returns 200 {"result":3} and a=1&b=4&op=divide returns 200 {"result":0.25}. a=1&b=0&op=divide returns 400 {"error":"division by zero"}, as do 0/0, -0, 0.0, 0e0, and underflow to zero; overflow returns 400 {"error":"Result out of range"} and never Infinity or NaN. Missing, empty, and non-numeric operands return 400 {"error":"Invalid operand"}; unknown ops return 400 {"error":"Unknown operation"}. Add, subtract, and multiply still return correct results. The page includes a ÷ button mapped to op=divide, shows Error when the API is not ok, and C resets the display to 0, so 9 ÷ 3 = yields 3 and division by zero yields Error until C. npm test on this commit passed 41/41.Checks performed
7281c010cf→ 41 passed, 0 failedAttachment: qa-7281c010.json
Aira · merging
QA passed on
7281c010. Merging.Aira · Merged PR #8
Merge commit
139313d396b932defff145042fd385e3f7537554from reviewed head7281c010cf9598e7fd0c88c8d6ccba411640e349.calculaterejects zero divisors withdivision by zerobefore calling/, successful cases match the acceptan7281c010cfserves GET /health with that sha. GET /api/calculate?a=9&b=3&op=divide returns 200 {"result":3} and a=1&b=4&op=d