Percentage #9

Closed
opened 2026-11-21 01:41:55 +00:00 by lab-admin · 15 comments
Owner

Add a percentage operation.

Requirements

  • API: op=percent returns a * b / 100 ("a percent of b").
  • UI: a % button that works like the other binary operators. Pressing 5, 0, %, 8, = shows 4.
  • Existing operations and error handling keep working.
  • Tests in the module, API and page.

Acceptance criteria

  1. /api/calculate?a=50&b=8&op=percent returns {"result":4}.
  2. /api/calculate?a=12.5&b=200&op=percent returns {"result":25}.
  3. Bad input still returns 400 with an error.
  4. The page has a working % button.
Add a percentage operation. ## Requirements - API: `op=percent` returns `a * b / 100` ("a percent of b"). - UI: a `%` button that works like the other binary operators. Pressing `5`, `0`, `%`, `8`, `=` shows `4`. - Existing operations and error handling keep working. - Tests in the module, API and page. ## Acceptance criteria 1. `/api/calculate?a=50&b=8&op=percent` returns `{"result":4}`. 2. `/api/calculate?a=12.5&b=200&op=percent` returns `{"result":25}`. 3. Bad input still returns 400 with an `error`. 4. The page has a working `%` button.
Collaborator

Aira · queued

Aira picked up this task. Branch aira/9-percentage.

**Aira · queued** Aira picked up this task. Branch `aira/9-percentage`.
Collaborator

Aira · planning

Orchestrator thread started (composer-2.5). Planning on aira/9-percentage.

T3 thread: mcp:launch:0c98aa9e51c3e6623cd2a099341ff4e84d1c9becbe47568b9859da96e0875c3b

**Aira · planning** Orchestrator thread started (composer-2.5). Planning on `aira/9-percentage`. T3 thread: `mcp:launch:0c98aa9e51c3e6623cd2a099341ff4e84d1c9becbe47568b9859da96e0875c3b`
Collaborator

Aira · Plan (round 1) at 308808f5

Added 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 percent function computing a percent of b (a * b / 100), op=percent on GET /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

  1. /api/calculate?a=50&b=8&op=percent returns {"result":4}.
  2. /api/calculate?a=12.5&b=200&op=percent returns {"result":25}.
  3. Bad input (missing, empty or non-numeric a/b, unknown op) still returns HTTP 400 with a JSON body containing an error string.
  4. The page has a working % button; keypad flow 5 → 0 → % → 8 → = shows 4 (50% of 8).

Design

Calculation module (lib/calculator.js)

  • Add percent(a, b) — pure numeric computation a * b / 100 (IEEE double semantics; satisfies integer and decimal cases such as 12.5% of 200).
  • Extend calculate(rawA, rawB, op):
    • Accept op === 'percent' alongside existing operations.
    • Parse operands with parseOperand (unchanged).
    • Run percent(a, b) and keep the existing finite-result guard (Result out of range) for pathological float overflow.
    • Reject unknown op with CalculatorError('Unknown operation') (unchanged).
  • Export percent alongside existing exports.
  • No operand-order special cases: a is the percentage value, b is the base amount (matches AC1–2 and the UI example).

HTTP layer (server.js)

  • No structural changes: /api/calculate already delegates to calculate(). Percent is picked up automatically once the module supports op=percent.
  • Confirm regression: invalid operands and unknown ops still map to 400 {"error": ...} via CalculatorError.

UI (public/index.html)

  • Add a % button on the keypad grid alongside +, −, ×, and ÷.
  • Extend click handling: else if (key === '%') commitOperand('percent'); using the existing pendingOp / evaluate pattern.
  • On successful =, display String(body.result) as today.
  • On failed API response (!res.ok), continue to set the display to Error (unchanged behaviour).
  • C continues to call reset() and restore display 0.

Test layout

File Purpose
test/calculator.test.js Unit tests for percent, calculate with op=percent, regressions for other ops.
test/server.test.js HTTP tests for AC1–2; regression for add/subtract/multiply/divide and invalid input (AC3).
test/ui.test.js % button presence, commitOperand('percent'), and existing API / error-display assertions.

Files to change

File Action
lib/calculator.js Modify — add percent, extend calculate dispatch.
server.js No change expected — verify via tests.
public/index.html Modify — % button, commitOperand('percent') in click handler.
test/calculator.test.js Modify — percent unit tests and invalid-op regression with percent.
test/server.test.js Modify — percent API acceptance cases (AC1–2).
test/ui.test.js Modify — % in required-button list; percent op wiring test.
docs/plans/issue-9.md Create — this plan.

No changes to package.json, CI workflows, or dependencies (Node built-ins only).

Test plan

Unit (test/calculator.test.js)

Case Assert
AC1 (module) percent(50, 8) === 4; calculate('50', '8', 'percent') === 4.
AC2 (module) percent(12.5, 200) === 25; calculate('12.5', '200', 'percent') === 25.
Regression Existing add/subtract/multiply/divide calculate tests unchanged; unknown op still throws CalculatorError.
Regression Invalid operands with percent mirror other operations (assert.throws with CalculatorError).
Edge Extreme magnitudes producing non-finite result throw CalculatorError('Result out of range') if applicable (same guard as multiply).

HTTP (test/server.test.js)

Case Request Expect
AC1 a=50&b=8&op=percent 200, { result: 4 }
AC2 a=12.5&b=200&op=percent 200, { result: 25 }
AC3 (regression) Existing invalid operand / unknown op tests 400, { error: string }
Regression Existing add/subtract/multiply/divide success tests unchanged expectations

UI / page (test/ui.test.js)

Case Assert
AC4 (controls) Extend required-button list to include %; HTML includes data-key="%").
AC4 (integration) Script includes commitOperand('percent') and /api/calculate with op: pendingOp.

Pre-push

  • Run npm test locally; all tests green before git push origin aira/9-percentage.

Risks

Risk Mitigation
Misinterpreting percent as b% of a vs a% of b Implement a * b / 100 per task spec; lock with AC1–2 and UI example (50, %, 8, = → 4).
Float rounding on 12.5 * 200 / 100 Use same JSON number / display path as other ops; assert exact 25 in tests (values are representable).
Grid layout with a fifth operation button Adjust keypad grid placement if % breaks digit / = layout; keep touch targets usable.
Confusing % in regex / data-key (special in RegExp) Escape % in UI button-list regex like other keys; match literal data-key="%".
Breaking /health or / Touch only calculator module and HTML/JS; regression server tests unchanged.

Attachment: plan-9-r1.md

**Aira · Plan (round 1) at `308808f5`** Added docs/plans/issue-9.md (percent op, % UI, unit/HTTP/UI test plan); committed and pushed to aira/9-percentage after npm test passed. <details><summary>docs/plans/issue-9.md</summary> # Issue #9: Percentage ## Goal Add a percentage operation alongside add, subtract, multiply, and divide: a pure `percent` function computing **a percent of b** (`a * b / 100`), `op=percent` on `GET /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 1. `/api/calculate?a=50&b=8&op=percent` returns `{"result":4}`. 2. `/api/calculate?a=12.5&b=200&op=percent` returns `{"result":25}`. 3. Bad input (missing, empty or non-numeric `a`/`b`, unknown `op`) still returns HTTP 400 with a JSON body containing an `error` string. 4. The page has a working `%` button; keypad flow `5` → `0` → `%` → `8` → `=` shows `4` (50% of 8). ## Design ### Calculation module (`lib/calculator.js`) - Add `percent(a, b)` — pure numeric computation `a * b / 100` (IEEE double semantics; satisfies integer and decimal cases such as 12.5% of 200). - Extend `calculate(rawA, rawB, op)`: - Accept `op === 'percent'` alongside existing operations. - Parse operands with `parseOperand` (unchanged). - Run `percent(a, b)` and keep the existing finite-result guard (`Result out of range`) for pathological float overflow. - Reject unknown `op` with `CalculatorError('Unknown operation')` (unchanged). - Export `percent` alongside existing exports. - No operand-order special cases: `a` is the percentage value, `b` is the base amount (matches AC1–2 and the UI example). ### HTTP layer (`server.js`) - No structural changes: `/api/calculate` already delegates to `calculate()`. Percent is picked up automatically once the module supports `op=percent`. - Confirm regression: invalid operands and unknown ops still map to `400 {"error": ...}` via `CalculatorError`. ### UI (`public/index.html`) - Add a `%` button on the keypad grid alongside `+`, `−`, `×`, and `÷`. - Extend click handling: `else if (key === '%') commitOperand('percent');` using the existing `pendingOp` / `evaluate` pattern. - On successful `=`, display `String(body.result)` as today. - On failed API response (`!res.ok`), continue to set the display to `Error` (unchanged behaviour). - `C` continues to call `reset()` and restore display `0`. ### Test layout | File | Purpose | |------|---------| | `test/calculator.test.js` | Unit tests for `percent`, `calculate` with `op=percent`, regressions for other ops. | | `test/server.test.js` | HTTP tests for AC1–2; regression for add/subtract/multiply/divide and invalid input (AC3). | | `test/ui.test.js` | `%` button presence, `commitOperand('percent')`, and existing API / error-display assertions. | ## Files to change | File | Action | |------|--------| | `lib/calculator.js` | **Modify** — add `percent`, extend `calculate` dispatch. | | `server.js` | **No change expected** — verify via tests. | | `public/index.html` | **Modify** — `%` button, `commitOperand('percent')` in click handler. | | `test/calculator.test.js` | **Modify** — percent unit tests and invalid-op regression with `percent`. | | `test/server.test.js` | **Modify** — percent API acceptance cases (AC1–2). | | `test/ui.test.js` | **Modify** — `%` in required-button list; percent op wiring test. | | `docs/plans/issue-9.md` | **Create** — this plan. | No changes to `package.json`, CI workflows, or dependencies (Node built-ins only). ## Test plan ### Unit (`test/calculator.test.js`) | Case | Assert | |------|--------| | AC1 (module) | `percent(50, 8) === 4`; `calculate('50', '8', 'percent') === 4`. | | AC2 (module) | `percent(12.5, 200) === 25`; `calculate('12.5', '200', 'percent') === 25`. | | Regression | Existing add/subtract/multiply/divide `calculate` tests unchanged; unknown `op` still throws `CalculatorError`. | | Regression | Invalid operands with `percent` mirror other operations (`assert.throws` with `CalculatorError`). | | Edge | Extreme magnitudes producing non-finite result throw `CalculatorError('Result out of range')` if applicable (same guard as multiply). | ### HTTP (`test/server.test.js`) | Case | Request | Expect | |------|---------|--------| | AC1 | `a=50&b=8&op=percent` | 200, `{ result: 4 }` | | AC2 | `a=12.5&b=200&op=percent` | 200, `{ result: 25 }` | | AC3 (regression) | Existing invalid operand / unknown `op` tests | 400, `{ error: string }` | | Regression | Existing add/subtract/multiply/divide success tests | unchanged expectations | ### UI / page (`test/ui.test.js`) | Case | Assert | |------|--------| | AC4 (controls) | Extend required-button list to include `%`; HTML includes `data-key="%")`. | | AC4 (integration) | Script includes `commitOperand('percent')` and `/api/calculate` with `op: pendingOp`. | ### Pre-push - Run `npm test` locally; all tests green before `git push origin aira/9-percentage`. ## Risks | Risk | Mitigation | |------|------------| | Misinterpreting percent as `b% of a` vs `a% of b` | Implement `a * b / 100` per task spec; lock with AC1–2 and UI example (`50`, `%`, `8`, `=` → `4`). | | Float rounding on `12.5 * 200 / 100` | Use same JSON number / display path as other ops; assert exact `25` in tests (values are representable). | | Grid layout with a fifth operation button | Adjust keypad grid placement if `%` breaks digit / `=` layout; keep touch targets usable. | | Confusing `%` in regex / `data-key` (special in RegExp) | Escape `%` in UI button-list regex like other keys; match literal `data-key="%"`. | | Breaking `/health` or `/` | Touch only calculator module and HTML/JS; regression server tests unchanged. | </details> Attachment: [plan-9-r1.md](https://aira-lab.cluster-dev.spkey.co/attachments/0f50436e-92b7-43d3-a288-c8c663652a81)
Collaborator

Aira · plan review

Plan pushed at 308808f5; independent Dodik plan review started.

**Aira · plan review** Plan pushed at `308808f5`; independent Dodik plan review started.
Collaborator

Aira · dodik-plan PASS on 308808f5

The issue #9 plan at 308808f is 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.

  • [minor] Existing operations are not a numbered criterion (docs/plans/issue-9.md): The requirement that add, subtract, multiply, and divide keep working is in the goal and in the unit and HTTP regression rows, while AC3 states only bad input. Add that those four operations still return their current results to a numbered acceptance criterion so every requirement is in the numbered list.
  • [minor] Stray parenthesis in the % button assertion (docs/plans/issue-9.md): The UI test-plan cell says the HTML includes data-key="%"). The button should be matched as data-key="%". Remove the extra closing parenthesis.
Checks performed
  • Mapped the API formula to AC1 and AC2, bad input (missing, empty, non-numeric, unknown op) to AC3, and the % button plus 50, %, 8, = flow to AC4.
  • Read lib/calculator.js: calculate dispatches add/subtract/multiply/divide, parses with parseOperand, rejects unknown ops and non-finite results, and exports the pure functions. percent(a, b) = a * b / 100 fits that shape, and the UI stores the first entry as a.
  • Read server.js: /api/calculate passes a, b, and op to calculate() and maps CalculatorError to 400 {error}. No HTTP change is required for op=percent.
  • Read public/index.html: operators call commitOperand, = calls evaluate with op: pendingOp, success displays String(body.result), failure displays Error, and C calls reset(). else if (key === '%') commitOperand('percent') matches that pattern and yields a=50, b=8.
  • Read test/calculator.test.js, test/server.test.js, and test/ui.test.js. The plan adds percent unit and HTTP cases and extends the static % button and commitOperand('percent') checks, and it keeps the existing success, invalid-input, unknown-op, Error, and clear assertions.
  • Ran npm test: 41 passed, 0 failed, including add/subtract/multiply/divide and the 400 error paths.
  • Confirmed the file list stays inside lib/calculator.js, public/index.html, the three test files, and this plan. No dependency, package.json, or CI changes.

Attachment: dodik-plan-308808f5.json

**Aira · dodik-plan PASS on `308808f5`** The issue #9 plan at 308808f is 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. - [minor] Existing operations are not a numbered criterion (docs/plans/issue-9.md): The requirement that add, subtract, multiply, and divide keep working is in the goal and in the unit and HTTP regression rows, while AC3 states only bad input. Add that those four operations still return their current results to a numbered acceptance criterion so every requirement is in the numbered list. - [minor] Stray parenthesis in the % button assertion (docs/plans/issue-9.md): The UI test-plan cell says the HTML includes data-key="%"). The button should be matched as data-key="%". Remove the extra closing parenthesis. <details><summary>Checks performed</summary> - Mapped the API formula to AC1 and AC2, bad input (missing, empty, non-numeric, unknown op) to AC3, and the % button plus 50, %, 8, = flow to AC4. - Read lib/calculator.js: calculate dispatches add/subtract/multiply/divide, parses with parseOperand, rejects unknown ops and non-finite results, and exports the pure functions. percent(a, b) = a * b / 100 fits that shape, and the UI stores the first entry as a. - Read server.js: /api/calculate passes a, b, and op to calculate() and maps CalculatorError to 400 {error}. No HTTP change is required for op=percent. - Read public/index.html: operators call commitOperand, = calls evaluate with op: pendingOp, success displays String(body.result), failure displays Error, and C calls reset(). else if (key === '%') commitOperand('percent') matches that pattern and yields a=50, b=8. - Read test/calculator.test.js, test/server.test.js, and test/ui.test.js. The plan adds percent unit and HTTP cases and extends the static % button and commitOperand('percent') checks, and it keeps the existing success, invalid-input, unknown-op, Error, and clear assertions. - Ran npm test: 41 passed, 0 failed, including add/subtract/multiply/divide and the 400 error paths. - Confirmed the file list stays inside lib/calculator.js, public/index.html, the three test files, and this plan. No dependency, package.json, or CI changes. </details> Attachment: [dodik-plan-308808f5.json](https://aira-lab.cluster-dev.spkey.co/attachments/f096084c-85b2-40c3-a928-bd77581e1fe5)
Collaborator

Aira · implementing

Plan approved by Dodik at 308808f5. Implementation started.

**Aira · implementing** Plan approved by Dodik at `308808f5`. Implementation started.
Collaborator

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** 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.
Collaborator

Aira · CI passed on 3b4c2820

  • ci / test (pull_request): success
**Aira · CI passed on `3b4c2820`** - ci / test (pull_request): success
Collaborator

Aira · review

CI is green on 3b4c2820. Independent Dodik and code review started.

**Aira · review** CI is green on `3b4c2820`. Independent Dodik and code review started.
Collaborator

Aira · dodik PASS on 3b4c2820

Commit 3b4c282 adds 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
  • Compared git diff origin/main...HEAD at 3b4c282 with docs/plans/issue-9.md
  • percent(a, b) is a * b / 100 and calculate accepts op=percent with the existing operand and finite-result checks
  • Live GET /api/calculate?a=50&b=8&op=percent returned 200 {"result":4}
  • Live GET /api/calculate?a=12.5&b=200&op=percent returned 200 {"result":25}
  • Live invalid, empty, and missing operands for op=percent, plus an unknown op, returned 400 with an error string; add and /health still succeed
  • Served page includes data-key="%" wired to commitOperand('percent'); simulated presses 5, 0, %, 8, = displayed 4
  • npm test: 46 passed, 0 failed, 0 skipped, 0 todo
  • Diff is only the plan, lib/calculator.js, public/index.html, and the three test files; no removed assertions, skips, or debug leftovers; README does not list operations so it needed no update

Attachment: dodik-3b4c2820.json

**Aira · dodik PASS on `3b4c2820`** Commit 3b4c282 adds 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. <details><summary>Checks performed</summary> - Compared git diff origin/main...HEAD at 3b4c282 with docs/plans/issue-9.md - percent(a, b) is a * b / 100 and calculate accepts op=percent with the existing operand and finite-result checks - Live GET /api/calculate?a=50&b=8&op=percent returned 200 {"result":4} - Live GET /api/calculate?a=12.5&b=200&op=percent returned 200 {"result":25} - Live invalid, empty, and missing operands for op=percent, plus an unknown op, returned 400 with an error string; add and /health still succeed - Served page includes data-key="%" wired to commitOperand('percent'); simulated presses 5, 0, %, 8, = displayed 4 - npm test: 46 passed, 0 failed, 0 skipped, 0 todo - Diff is only the plan, lib/calculator.js, public/index.html, and the three test files; no removed assertions, skips, or debug leftovers; README does not list operations so it needed no update </details> Attachment: [dodik-3b4c2820.json](https://aira-lab.cluster-dev.spkey.co/attachments/3cca946a-1f9b-41c3-9e47-f5db008b3cd6)
Collaborator

Aira · reviewer PASS on 3b4c2820

The percentage feature adds a minimal percent function and op=percent dispatch 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. Reviewed git diff origin/main...HEAD at 3b4c2820, read lib/calculator.js, public/index.html, and server.js delegation path, ran npm test (46/46 pass), and spot-checked negative operands, zero base, and overflow handling.

Checks performed
  • git diff origin/main...3b4c2820bf750d9ce58092f1caaac019af701779 reviewed for logic, UI wiring, and test coverage
  • npm test — 46 tests, 0 failures
  • Manual calculator edge checks: negative percent, zero base, overflow throws Result out of range
  • API contract unchanged for invalid/missing operands and unknown op (covered by existing and new tests)
  • UI keypad grid: % button and = span-3 layout; commitOperand('percent') and fetch with pendingOp
  • No server.js changes required; /api/calculate delegates to calculate()

Attachment: reviewer-3b4c2820.json

**Aira · reviewer PASS on `3b4c2820`** The percentage feature adds a minimal `percent` function and `op=percent` dispatch 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. Reviewed `git diff origin/main...HEAD` at 3b4c2820, read `lib/calculator.js`, `public/index.html`, and `server.js` delegation path, ran `npm test` (46/46 pass), and spot-checked negative operands, zero base, and overflow handling. <details><summary>Checks performed</summary> - git diff origin/main...3b4c2820bf750d9ce58092f1caaac019af701779 reviewed for logic, UI wiring, and test coverage - npm test — 46 tests, 0 failures - Manual calculator edge checks: negative percent, zero base, overflow throws Result out of range - API contract unchanged for invalid/missing operands and unknown op (covered by existing and new tests) - UI keypad grid: % button and = span-3 layout; commitOperand('percent') and fetch with pendingOp - No server.js changes required; /api/calculate delegates to calculate() </details> Attachment: [reviewer-3b4c2820.json](https://aira-lab.cluster-dev.spkey.co/attachments/c11928e2-c3a1-4494-b9e1-21f722af753c)
Collaborator

Aira · qa

Dodik and the reviewer passed on 3b4c2820. Preview deployed at http://127.0.0.1:40981; QA started.

**Aira · qa** Dodik and the reviewer passed on `3b4c2820`. Preview deployed at http://127.0.0.1:40981; QA started.
Collaborator

Aira · qa PASS on 3b4c2820

Commit 3b4c2820bf serves 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
  • GET http://127.0.0.1:40981/health -> 200 {"ok":true,"sha":"3b4c2820bf750d9ce58092f1caaac019af701779"}
  • GET http://127.0.0.1:40981/ -> 200 text/html with button data-key="%" calling commitOperand('percent'), and = fetching /api/calculate?a&b&op
  • GET /api/calculate?a=50&b=8&op=percent -> 200 {"result":4}
  • GET /api/calculate?a=12.5&b=200&op=percent -> 200 {"result":25}
  • GET /api/calculate?a=2&b=3&op=add -> 200 {"result":5}
  • GET /api/calculate?a=9&b=4&op=subtract -> 200 {"result":5}
  • GET /api/calculate?a=6&b=7&op=multiply -> 200 {"result":42}
  • GET /api/calculate?a=8&b=2&op=divide -> 200 {"result":4}
  • GET /api/calculate?a=0&b=8&op=percent -> 200 {"result":0}
  • GET /api/calculate?a=100&b=8&op=percent -> 200 {"result":8}
  • GET /api/calculate?a=200&b=50&op=percent -> 200 {"result":100}
  • GET /api/calculate?a=-50&b=8&op=percent -> 200 {"result":-4}
  • GET /api/calculate?a=50&b=-8&op=percent -> 200 {"result":-4}
  • GET /api/calculate?a=0&b=0&op=percent -> 200 {"result":0}
  • GET /api/calculate?a=1.5&b=10&op=percent -> 200 {"result":0.15}
  • GET /api/calculate?a=33.333&b=3&op=percent -> 200 {"result":0.9999899999999999}
  • GET /api/calculate?a=-25&b=-40&op=percent -> 200 {"result":10}
  • GET /api/calculate?b=8&op=percent -> 400 {"error":"Invalid operand"}
  • GET /api/calculate?a=50&op=percent -> 400 {"error":"Invalid operand"}
  • GET /api/calculate?a=50&b=8 -> 400 {"error":"Unknown operation"}
  • GET /api/calculate?a=&b=8&op=percent -> 400 {"error":"Invalid operand"}
  • GET /api/calculate?a=50&b=&op=percent -> 400 {"error":"Invalid operand"}
  • GET /api/calculate?a=50&b=8&op= -> 400 {"error":"Unknown operation"}
  • GET /api/calculate?a=foo&b=8&op=percent -> 400 {"error":"Invalid operand"}
  • GET /api/calculate?a=50&b=bar&op=percent -> 400 {"error":"Invalid operand"}
  • GET /api/calculate?a=50&b=8&op=modulo -> 400 {"error":"Unknown operation"}
  • GET /api/calculate?a=2&b=3&op=percentx -> 400 {"error":"Unknown operation"}
  • GET /api/calculate?a=1&b=0&op=divide -> 400 {"error":"division by zero"}
  • GET /api/calculate?a=x&b=1&op=add -> 400 {"error":"Invalid operand"}
  • GET /api/calculate -> 400 {"error":"Unknown operation"}
  • GET /api/calculate?a=%2050&b=8&op=percent -> 200 {"result":4}
  • GET /api/calculate?a=50&b=8&op=PERCENT -> 400 {"error":"Unknown operation"}
  • GET /api/calculate?a=50&b=8&op=Percent -> 400 {"error":"Unknown operation"}
  • npm test -> 46 pass, 0 fail, including percent module, API, and page tests

Attachment: qa-3b4c2820.json

**Aira · qa PASS on `3b4c2820`** Commit 3b4c2820bf750d9ce58092f1caaac019af701779 serves 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. <details><summary>Checks performed</summary> - GET http://127.0.0.1:40981/health -> 200 {"ok":true,"sha":"3b4c2820bf750d9ce58092f1caaac019af701779"} - GET http://127.0.0.1:40981/ -> 200 text/html with button data-key="%" calling commitOperand('percent'), and = fetching /api/calculate?a&b&op - GET /api/calculate?a=50&b=8&op=percent -> 200 {"result":4} - GET /api/calculate?a=12.5&b=200&op=percent -> 200 {"result":25} - GET /api/calculate?a=2&b=3&op=add -> 200 {"result":5} - GET /api/calculate?a=9&b=4&op=subtract -> 200 {"result":5} - GET /api/calculate?a=6&b=7&op=multiply -> 200 {"result":42} - GET /api/calculate?a=8&b=2&op=divide -> 200 {"result":4} - GET /api/calculate?a=0&b=8&op=percent -> 200 {"result":0} - GET /api/calculate?a=100&b=8&op=percent -> 200 {"result":8} - GET /api/calculate?a=200&b=50&op=percent -> 200 {"result":100} - GET /api/calculate?a=-50&b=8&op=percent -> 200 {"result":-4} - GET /api/calculate?a=50&b=-8&op=percent -> 200 {"result":-4} - GET /api/calculate?a=0&b=0&op=percent -> 200 {"result":0} - GET /api/calculate?a=1.5&b=10&op=percent -> 200 {"result":0.15} - GET /api/calculate?a=33.333&b=3&op=percent -> 200 {"result":0.9999899999999999} - GET /api/calculate?a=-25&b=-40&op=percent -> 200 {"result":10} - GET /api/calculate?b=8&op=percent -> 400 {"error":"Invalid operand"} - GET /api/calculate?a=50&op=percent -> 400 {"error":"Invalid operand"} - GET /api/calculate?a=50&b=8 -> 400 {"error":"Unknown operation"} - GET /api/calculate?a=&b=8&op=percent -> 400 {"error":"Invalid operand"} - GET /api/calculate?a=50&b=&op=percent -> 400 {"error":"Invalid operand"} - GET /api/calculate?a=50&b=8&op= -> 400 {"error":"Unknown operation"} - GET /api/calculate?a=foo&b=8&op=percent -> 400 {"error":"Invalid operand"} - GET /api/calculate?a=50&b=bar&op=percent -> 400 {"error":"Invalid operand"} - GET /api/calculate?a=50&b=8&op=modulo -> 400 {"error":"Unknown operation"} - GET /api/calculate?a=2&b=3&op=percentx -> 400 {"error":"Unknown operation"} - GET /api/calculate?a=1&b=0&op=divide -> 400 {"error":"division by zero"} - GET /api/calculate?a=x&b=1&op=add -> 400 {"error":"Invalid operand"} - GET /api/calculate -> 400 {"error":"Unknown operation"} - GET /api/calculate?a=%2050&b=8&op=percent -> 200 {"result":4} - GET /api/calculate?a=50&b=8&op=PERCENT -> 400 {"error":"Unknown operation"} - GET /api/calculate?a=50&b=8&op=Percent -> 400 {"error":"Unknown operation"} - npm test -> 46 pass, 0 fail, including percent module, API, and page tests </details> Attachment: [qa-3b4c2820.json](https://aira-lab.cluster-dev.spkey.co/attachments/32826194-1baa-459f-8d22-4c17593301eb)
Collaborator

Aira · merging

QA passed on 3b4c2820. Merging.

**Aira · merging** QA passed on `3b4c2820`. Merging.
Collaborator

Aira · Merged PR #13

Merge commit 4b16d0d214cefeca0c57013b06f18b5db70f41cb from reviewed head 3b4c2820bf750d9ce58092f1caaac019af701779.

Gate Verdict Summary
ci pass ci / test (pull_request)
dodik pass Commit 3b4c282 adds 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 th
reviewer pass The percentage feature adds a minimal percent function and op=percent dispatch consistent with existing binary operations, a % keypad control using the sa
qa pass Commit 3b4c2820bf serves a working percent operation. GET /health reports that sha. op=percent returns a*b/100, including {"result
**Aira · Merged PR #13** Merge commit `4b16d0d214cefeca0c57013b06f18b5db70f41cb` from reviewed head `3b4c2820bf750d9ce58092f1caaac019af701779`. | Gate | Verdict | Summary | |---|---|---| | ci | pass | ci / test (pull_request) | | dodik | pass | Commit 3b4c282 adds 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 th | | reviewer | pass | The percentage feature adds a minimal `percent` function and `op=percent` dispatch consistent with existing binary operations, a `%` keypad control using the sa | | qa | pass | Commit 3b4c2820bf750d9ce58092f1caaac019af701779 serves a working percent operation. GET /health reports that sha. op=percent returns a*b/100, including {"result |
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/web-calculator#9
No description provided.