Percentage #5
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-2#5
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/5-percentage.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/5-percentage.T3 thread:
mcp:launch:03cc6f60b08fbef33dbf826fb7bbff1a071a850f17f77048bf44e0b8b4c9d4c4Aira · Plan (round 1) at
c1b6f3c7Wrote docs/plans/issue-5.md for op=percent (a*b/100), UI % button, and module/API/UI tests; committed and pushed aira/5-percentage.
docs/plans/issue-5.md
Issue #5: Percentage
Goal
Add a percentage operation end to end: a pure
percentfunction inlib/calculator.jsimplementinga * b / 100(“a percent of b”),GET /api/calculatesupport forop=percent, and a%button in the UI wired like the other binary operators. The flow5,0,%,8,=must show4(50% of 8). Addition, subtraction, multiplication, division, and existing error handling remain unchanged.Acceptance criteria
GET /api/calculate?a=50&b=8&op=percentreturns HTTP 200 with body{"result":4}.GET /api/calculate?a=12.5&b=200&op=percentreturns HTTP 200 with body{"result":25}.a/b, unknownop) still returns HTTP 400 with anerrorfield in the body./has a working%button that selectsop=percentvia the same operator flow as+,−,×, and÷.Design
Calculator module (
lib/calculator.js)percent(a, b)— returnsa * b / 100for finite numeric operands (caller supplies parsed numbers).calculate(op, a, b):op === 'percent'in the allowed-operation check (alongsideadd,subtract,multiply, anddivide).percentwhenop === 'percent'; keep existing branches for other operations.parseNumber, operand validation, and the non-finite result guard after computation.opstill returns{ error: 'unknown operation' }.percentfrommodule.exportsalongside existing exports.HTTP layer (
server.js)/api/calculatealready delegates tocalculateand mapsout.errorto HTTP 400 with{ error: out.error }.UI (
public/index.html)%key to the button grid inlabels, consistent with other operators.onKeyso%callspressOperator('percent')(samewaitingForSecondflow as other operators).labelsso the 4-column grid still includes all digits, operators (+,−,×,÷,%),C,=, and.without removing existing keys.Operand mapping for the UI flow (unchanged pattern): first number entered becomes
a(the percentage value), second becomesb(the value to take that percent of). Example:50,%,8,=→ APIa=50&b=8&op=percent→4.Files to change
lib/calculator.jspercent; extendcalculateforop=percent; exportpercent.server.jspublic/index.html%button; wirepressOperator('percent'); adjustlabelslayout.test/calculator.test.jspercent,calculate('percent', ...), and regression for other ops.test/server.test.jstest/ui.test.js%button present; script referencespercent; regression for existing buttons.Test plan
Unit tests (
test/calculator.test.js)percent(50, 8) === 4percent(12.5, 200) === 25calculate('percent', '50', '8')→{ result: 4 }calculate('percent', '12.5', '200')→{ result: 25 }calculate('pow', ...)still unknown errorcalculate('percent', 'x', '8')→{ error: 'invalid a' }calculate('percent', '50', 'bad')→{ error: 'invalid b' }HTTP tests (
test/server.test.js)Use existing
withServer+fetchpattern:?a=50&b=8&op=percent{ result: 4 }?a=12.5&b=200&op=percent{ result: 25 }?a=x&b=8&op=percent{ error: ... }?a=50&b=bad&op=percent{ error: ... }?a=2&b=3&op=add?a=2&b=5&op=subtract?a=6&b=7&op=multiply?a=9&b=3&op=divide?a=1&b=2&op=powerrorstringUI / page tests (
test/ui.test.js)labelsincludes'%'pressOperator('percent')+,−,×,÷,=,C, andfetchto/api/calculateRun
npm testlocally before every push; all tests must pass.Risks
50 * 8 / 100)labelsto keep a sensible 4-column grid; UI test checks all prior buttons remain.%label vs APIop=percentop=percent; UI label is display-only; tests assert HTML contains%andpressOperator('percent').ais percentage value,bis base; acceptance example50 % of 8→ 4.calculateonly; run full existing test suite.Implementation order (for later steps)
lib/calculator.js+test/calculator.test.jstest/server.test.js(server unchanged)public/index.htmlUI +test/ui.test.jsnpm test, then push branchaira/5-percentageAttachment: plan-5-r1.md
Aira · plan review
Plan pushed at
c1b6f3c7; independent Dodik plan review started.Aira · dodik-plan PASS on
c1b6f3c7The issue #5 plan maps the percentage API, the % button flow (50% of 8 shows 4), and unchanged error handling onto four testable acceptance criteria. The design matches lib/calculator.js, server.js, and public/index.html, and the unit, HTTP, and page tests cover the success cases, bad input, and existing operations without extra scope.
Checks performed
Attachment: dodik-plan-c1b6f3c7.json
Aira · implementing
Plan approved by Dodik at
c1b6f3c7. Implementation started.Aira · ci
Ready for review at
6939abf5(PR #13). Waiting for CI.Implemented percent in calculator.js (a*b/100), % button with pressOperator('percent'), and unit/server/UI tests; npm test 56/56 pass; pushed to aira/5-percentage.
Aira · CI passed on
6939abf5Aira · review
CI is green on
6939abf5. Independent Dodik and code review started.