Percentage #9
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#9
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 a percentage operation.
Requirements
op=percentreturnsa * b / 100("a percent of b").%button that works like the other binary operators. Pressing5,0,%,8,=shows4.Acceptance criteria
/api/calculate?a=50&b=8&op=percentreturns{"result":4}./api/calculate?a=12.5&b=200&op=percentreturns{"result":25}.error.%button.Aira · queued
Aira picked up this task. Branch
aira/9-percentage.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/9-percentage.T3 thread:
mcp:launch:0c98aa9e51c3e6623cd2a099341ff4e84d1c9becbe47568b9859da96e0875c3bAira · Plan (round 1) at
308808f5Added docs/plans/issue-9.md (percent op, % UI, unit/HTTP/UI test plan); committed and pushed to aira/9-percentage after npm test passed.
docs/plans/issue-9.md
Issue #9: Percentage
Goal
Add a percentage operation alongside add, subtract, multiply, and divide: a pure
percentfunction computing a percent of b (a * b / 100),op=percentonGET /api/calculate, and a%button on the calculator UI following the same operand / equals flow as the other binary operations. Preserve existing operations,/health,/static serving, and standard invalid-input error handling.Acceptance criteria
/api/calculate?a=50&b=8&op=percentreturns{"result":4}./api/calculate?a=12.5&b=200&op=percentreturns{"result":25}.a/b, unknownop) still returns HTTP 400 with a JSON body containing anerrorstring.%button; keypad flow5→0→%→8→=shows4(50% of 8).Design
Calculation module (
lib/calculator.js)percent(a, b)— pure numeric computationa * b / 100(IEEE double semantics; satisfies integer and decimal cases such as 12.5% of 200).calculate(rawA, rawB, op):op === 'percent'alongside existing operations.parseOperand(unchanged).percent(a, b)and keep the existing finite-result guard (Result out of range) for pathological float overflow.opwithCalculatorError('Unknown operation')(unchanged).percentalongside existing exports.ais the percentage value,bis the base amount (matches AC1–2 and the UI example).HTTP layer (
server.js)/api/calculatealready delegates tocalculate(). Percent is picked up automatically once the module supportsop=percent.400 {"error": ...}viaCalculatorError.UI (
public/index.html)%button on the keypad grid alongside+,−,×, and÷.else if (key === '%') commitOperand('percent');using the existingpendingOp/evaluatepattern.=, displayString(body.result)as today.!res.ok), continue to set the display toError(unchanged behaviour).Ccontinues to callreset()and restore display0.Test layout
test/calculator.test.jspercent,calculatewithop=percent, regressions for other ops.test/server.test.jstest/ui.test.js%button presence,commitOperand('percent'), and existing API / error-display assertions.Files to change
lib/calculator.jspercent, extendcalculatedispatch.server.jspublic/index.html%button,commitOperand('percent')in click handler.test/calculator.test.jspercent.test/server.test.jstest/ui.test.js%in required-button list; percent op wiring test.docs/plans/issue-9.mdNo changes to
package.json, CI workflows, or dependencies (Node built-ins only).Test plan
Unit (
test/calculator.test.js)percent(50, 8) === 4;calculate('50', '8', 'percent') === 4.percent(12.5, 200) === 25;calculate('12.5', '200', 'percent') === 25.calculatetests unchanged; unknownopstill throwsCalculatorError.percentmirror other operations (assert.throwswithCalculatorError).CalculatorError('Result out of range')if applicable (same guard as multiply).HTTP (
test/server.test.js)a=50&b=8&op=percent{ result: 4 }a=12.5&b=200&op=percent{ result: 25 }optests{ error: string }UI / page (
test/ui.test.js)%; HTML includesdata-key="%").commitOperand('percent')and/api/calculatewithop: pendingOp.Pre-push
npm testlocally; all tests green beforegit push origin aira/9-percentage.Risks
b% of avsa% of ba * b / 100per task spec; lock with AC1–2 and UI example (50,%,8,=→4).12.5 * 200 / 10025in tests (values are representable).%breaks digit /=layout; keep touch targets usable.%in regex /data-key(special in RegExp)%in UI button-list regex like other keys; match literaldata-key="%"./healthor/Attachment: plan-9-r1.md
Aira · plan review
Plan pushed at
308808f5; independent Dodik plan review started.Aira · dodik-plan PASS on
308808f5The issue #9 plan at
308808fis consistent with the percentage task and the current code. AC1–AC4 cover op=percent as a*b/100 (50% of 8 is 4, 12.5% of 200 is 25), bad input still returning HTTP 400 with an error string, and a % button whose 5, 0, %, 8, = flow shows 4. The design names lib/calculator.js and public/index.html, matches the existing dispatch, parseOperand, finite-result guard, and commitOperand/evaluate flow, and correctly expects no server.js change because GET /api/calculate already forwards op to calculate(). Unit and HTTP tests prove AC1–AC2, existing invalid-input tests plus percent operand failures prove AC3, and the page tests prove AC4 the same way the other operators are checked. Scope stays on the calculator module, the page, and the three test files. npm test is green (41 passing) on the regression suite the plan keeps.Checks performed
Attachment: dodik-plan-308808f5.json
Aira · implementing
Plan approved by Dodik at
308808f5. Implementation started.Aira · ci
Ready for review at
3b4c2820(PR #13). Waiting for CI.Added percent op (a*b/100), % UI button, and tests covering AC1–4; npm test 46/46; pushed feat commit to aira/9-percentage.
Aira · CI passed on
3b4c2820Aira · review
CI is green on
3b4c2820. Independent Dodik and code review started.Aira · dodik PASS on
3b4c2820Commit
3b4c282adds op=percent as a*b/100 in lib/calculator.js, a % keypad button that commits the pending percent operation, and module, API, and page tests that cover the new behaviour. All four acceptance criteria hold: 50% of 8 is 4, 12.5% of 200 is 25, bad input still returns 400 with an error, and the keypad sequence 5, 0, %, 8, = displays 4. npm test passed 46 tests with none skipped or weakened, and the diff stays within the plan.Checks performed
3b4c282with docs/plans/issue-9.mdAttachment: dodik-3b4c2820.json
Aira · reviewer PASS on
3b4c2820The percentage feature adds a minimal
percentfunction andop=percentdispatch consistent with existing binary operations, a%keypad control using the same commit/evaluate flow, and tests covering acceptance criteria plus invalid-input and overflow regressions. Reviewedgit diff origin/main...HEADat3b4c2820, readlib/calculator.js,public/index.html, andserver.jsdelegation path, rannpm test(46/46 pass), and spot-checked negative operands, zero base, and overflow handling.Checks performed
Attachment: reviewer-3b4c2820.json
Aira · qa
Dodik and the reviewer passed on
3b4c2820. Preview deployed at http://127.0.0.1:40981; QA started.Aira · qa PASS on
3b4c2820Commit
3b4c2820bfserves a working percent operation. GET /health reports that sha. op=percent returns a*b/100, including {"result":4} for 50 and 8 and {"result":25} for 12.5 and 200. Missing, empty, and non-numeric operands and unknown ops return 400 with an error field, and add, subtract, multiply, and divide still succeed. The page includes a % button that stores op=percent like the other binary operators, so the 5, 0, %, 8, = sequence requests a=50&b=8&op=percent and displays 4. npm test passed 46 tests, including percent cases for the module, API, and page.Checks performed
Attachment: qa-3b4c2820.json
Aira · merging
QA passed on
3b4c2820. Merging.Aira · Merged PR #13
Merge commit
4b16d0d214cefeca0c57013b06f18b5db70f41cbfrom reviewed head3b4c2820bf750d9ce58092f1caaac019af701779.3b4c282adds op=percent as a*b/100 in lib/calculator.js, a % keypad button that commits the pending percent operation, and module, API, and page tests thpercentfunction andop=percentdispatch consistent with existing binary operations, a%keypad control using the sa3b4c2820bfserves a working percent operation. GET /health reports that sha. op=percent returns a*b/100, including {"result