Percentage #5

Closed
opened 2026-11-21 03:35:34 +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/5-percentage.

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

Aira · planning

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

T3 thread: mcp:launch:ccc88428bdabe1bf85b7b7566d287bb2a37466164be54adc1082889e38578695

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

Aira · Plan (round 1) at 9ece0131

Added docs/plans/issue-5.md for the percent operation (API, UI, tests, risks), committed, and pushed aira/5-percentage.

docs/plans/issue-5.md

Issue #5: Percentage

Goal

Extend the calculator with a percentage operation end-to-end: handle op=percent in lib/calculator.js as a percent of b (a * b / 100), expose it through the existing GET /api/calculate route (unchanged contract), and add a % keypad button that behaves like +, −, ×, and ÷. The flow 5, 0, %, 8, = must display 4 via the API (50% of 8). Addition, subtraction, multiplication, division, validation, and other error responses remain unchanged.

Acceptance criteria

  1. GET /api/calculate?a=50&b=8&op=percent returns HTTP 200 with body {"result":4}.
  2. GET /api/calculate?a=12.5&b=200&op=percent returns HTTP 200 with body {"result":25}.
  3. Bad input (missing or empty a/b, non-numeric operands, unknown op, missing op) still returns HTTP 400 with an error string in the JSON body.
  4. The page at / includes a working % button; 5 0 % 8 = shows 4 on the display (via GET /api/calculate?a=50&b=8&op=percent).

Design

Calculator module (lib/calculator.js)

  • Extend calculate(a, b, op) with a branch for op === 'percent':
    • After parseNumber yields x and y, compute result = (x * y) / 100.
    • If the result is not finite, throw result out of range (parity with add / subtract / multiply / divide).
  • No special-case zero handling is required (unlike divide); 0 operands are valid.
  • Unknown-op path continues to accept only known ops; percent becomes the fifth supported operation.
  • Keep parseNumber unchanged.

HTTP layer (server.js)

  • No route or validation changes required: handleCalculate already passes op through to calculate; operand and unknown-op errors are mapped to HTTP 400 via existing catch (err) → sendJson(400, { error: err.message }).
  • Confirm successful percent returns 200 {"result": <number>} for AC1–2.

UI (public/index.html)

  • Add a keypad button labeled % with data-key="% consistent with other operators.
  • Extend the operator click handler: include % in the operator key set and map it to pendingOp = 'percent' in opMap alongside existing operators.
  • On =, continue fetch('/api/calculate?...') with op from pendingOp (no special error display for percent; use existing error path).
  • Example flow:
    • 5 → 0 → % → 8 → = → GET /api/calculate?a=50&b=8&op=percent → display 4.
  • Operand semantics match other binary ops: first operand is the percentage value (a), second is the base (b).

Keypad layout

  • Current grid: operator column has ÷, ×, −, +; C and = share the bottom row with digits. Add % on an open or operator-adjacent cell without removing C, digits, ., =, or existing operators — e.g. place % beside an existing operator row following the same button styling as issue #4’s ÷ placement pattern.
  • Unit/UI tests assert data-key="%" is present in served HTML.

Test layout

File Scope
test/calculator.test.js Unit tests for percent, decimals, regressions on other ops
test/server.test.js HTTP tests for percent success (AC1–2), bad input (AC3), regressions
test/ui.test.js % button in HTML; static checks for percent op mapping

Files to change

File Action
lib/calculator.js Modify — add percent branch (x * y / 100)
public/index.html Modify — % button, operator mapping to percent
test/calculator.test.js Modify — percent unit cases + regressions
test/server.test.js Modify — percent API cases (AC1–2), bad input with op=percent (AC3)
test/ui.test.js Modify — add % to REQUIRED_KEYS; assert percent in operator mapping

Test plan

Unit (test/calculator.test.js)

Case Maps to
calculate('50', '8', 'percent') → 4 AC1 (module)
calculate('12.5', '200', 'percent') → 25 AC2 (module)
calculate('0', '100', 'percent') → 0 Edge: zero percent
calculate('100', '0', 'percent') → 0 Edge: zero base
calculate('2', '3', 'add') → 5 Regression
calculate('9', '3', 'divide') → 3 Regression
calculate('1', '2', 'pow') throws unknown operation Regression
Optional: percent overflow → out of range Parity with other ops

HTTP (test/server.test.js)

Request Expected Maps to
?a=50&b=8&op=percent → 200, result: 4 AC1
?a=12.5&b=200&op=percent → 200, result: 25 AC2
?a=x&b=2&op=percent → 400, error string AC3
?a=1&op=percent (missing b) → 400, error string AC3
?a=1&b=2&op=foo → 400, error string AC3
?a=2&b=3&op=add → 200, result: 5 Regression

All existing server tests (health, index, 404, prior op errors, divide) must still pass.

UI (test/ui.test.js)

Case Maps to
Served HTML includes data-key="%" AC4 (button)
HTML/inline script maps % to percent (e.g. match on 'percent' in opMap or operator handler) AC4 (wiring)
Existing REQUIRED_KEYS (other ops), /api/calculate fetch remain Regression

Full suite: npm test must pass before push.

Risks

Risk Mitigation
Wrong formula (e.g. b * a / 100 vs a * b / 100, or a / 100 only) Task defines “a percent of b”; AC1 pins 50 and 8 → 4; unit and HTTP tests lock semantics
Operand order reversed in UI (b as percent, a as base) Match existing binary-op pattern: first entered value is a, second is b; document flow in design; AC4 flow 50 % 8 → 4
Float rounding noise AC uses exact values (4, 25); use assert.equal / deepEqual like other ops
Keypad layout regression Keep all existing keys; only add/reposition %
Breaking add / subtract / multiply / divide or validation Run full test suite; extend rather than replace operator mapping
% in regex or HTML test escaping Escape % in RegExp for REQUIRED_KEYS loop like other special chars if needed (literal % in attribute is fine)

Implementation order

  1. lib/calculator.js percent branch + unit tests in test/calculator.test.js
  2. test/server.test.js for AC1–3 and regressions
  3. public/index.html % button and operator mapping + test/ui.test.js
  4. Full npm test, then push aira/5-percentage

Attachment: plan-5-r1.md

**Aira · Plan (round 1) at `9ece0131`** Added docs/plans/issue-5.md for the percent operation (API, UI, tests, risks), committed, and pushed aira/5-percentage. <details><summary>docs/plans/issue-5.md</summary> # Issue #5: Percentage ## Goal Extend the calculator with a percentage operation end-to-end: handle `op=percent` in `lib/calculator.js` as **a percent of b** (`a * b / 100`), expose it through the existing `GET /api/calculate` route (unchanged contract), and add a `%` keypad button that behaves like `+`, `−`, `×`, and `÷`. The flow `5`, `0`, `%`, `8`, `=` must display `4` via the API (`50% of 8`). Addition, subtraction, multiplication, division, validation, and other error responses remain unchanged. ## Acceptance criteria 1. `GET /api/calculate?a=50&b=8&op=percent` returns HTTP 200 with body `{"result":4}`. 2. `GET /api/calculate?a=12.5&b=200&op=percent` returns HTTP 200 with body `{"result":25}`. 3. Bad input (missing or empty `a`/`b`, non-numeric operands, unknown `op`, missing `op`) still returns HTTP 400 with an `error` string in the JSON body. 4. The page at `/` includes a working `%` button; `5` `0` `%` `8` `=` shows `4` on the display (via `GET /api/calculate?a=50&b=8&op=percent`). ## Design ### Calculator module (`lib/calculator.js`) - Extend `calculate(a, b, op)` with a branch for `op === 'percent'`: - After `parseNumber` yields `x` and `y`, compute `result = (x * y) / 100`. - If the result is not finite, throw `result out of range` (parity with add / subtract / multiply / divide). - No special-case zero handling is required (unlike divide); `0` operands are valid. - Unknown-op path continues to accept only known ops; `percent` becomes the fifth supported operation. - Keep `parseNumber` unchanged. ### HTTP layer (`server.js`) - No route or validation changes required: `handleCalculate` already passes `op` through to `calculate`; operand and unknown-op errors are mapped to HTTP 400 via existing `catch (err) → sendJson(400, { error: err.message })`. - Confirm successful percent returns `200 {"result": <number>}` for AC1–2. ### UI (`public/index.html`) - Add a keypad button labeled `%` with `data-key="%` consistent with other operators. - Extend the operator click handler: include `%` in the operator key set and map it to `pendingOp = 'percent'` in `opMap` alongside existing operators. - On `=`, continue `fetch('/api/calculate?...')` with `op` from `pendingOp` (no special error display for percent; use existing error path). - Example flow: - `5` → `0` → `%` → `8` → `=` → `GET /api/calculate?a=50&b=8&op=percent` → display `4`. - Operand semantics match other binary ops: first operand is the percentage value (`a`), second is the base (`b`). ### Keypad layout - Current grid: operator column has `÷`, `×`, `−`, `+`; `C` and `=` share the bottom row with digits. Add `%` on an open or operator-adjacent cell without removing `C`, digits, `.`, `=`, or existing operators — e.g. place `%` beside an existing operator row following the same button styling as issue #4’s `÷` placement pattern. - Unit/UI tests assert `data-key="%"` is present in served HTML. ### Test layout | File | Scope | |------|--------| | `test/calculator.test.js` | Unit tests for `percent`, decimals, regressions on other ops | | `test/server.test.js` | HTTP tests for percent success (AC1–2), bad input (AC3), regressions | | `test/ui.test.js` | `%` button in HTML; static checks for `percent` op mapping | ## Files to change | File | Action | |------|--------| | `lib/calculator.js` | **Modify** — add `percent` branch (`x * y / 100`) | | `public/index.html` | **Modify** — `%` button, operator mapping to `percent` | | `test/calculator.test.js` | **Modify** — percent unit cases + regressions | | `test/server.test.js` | **Modify** — percent API cases (AC1–2), bad input with `op=percent` (AC3) | | `test/ui.test.js` | **Modify** — add `%` to `REQUIRED_KEYS`; assert `percent` in operator mapping | ## Test plan ### Unit (`test/calculator.test.js`) | Case | Maps to | |------|---------| | `calculate('50', '8', 'percent')` → `4` | AC1 (module) | | `calculate('12.5', '200', 'percent')` → `25` | AC2 (module) | | `calculate('0', '100', 'percent')` → `0` | Edge: zero percent | | `calculate('100', '0', 'percent')` → `0` | Edge: zero base | | `calculate('2', '3', 'add')` → `5` | Regression | | `calculate('9', '3', 'divide')` → `3` | Regression | | `calculate('1', '2', 'pow')` throws unknown operation | Regression | | Optional: percent overflow → `out of range` | Parity with other ops | ### HTTP (`test/server.test.js`) | Request | Expected | Maps to | |---------|----------|---------| | `?a=50&b=8&op=percent` → 200, `result: 4` | AC1 | | `?a=12.5&b=200&op=percent` → 200, `result: 25` | AC2 | | `?a=x&b=2&op=percent` → 400, `error` string | AC3 | | `?a=1&op=percent` (missing `b`) → 400, `error` string | AC3 | | `?a=1&b=2&op=foo` → 400, `error` string | AC3 | | `?a=2&b=3&op=add` → 200, `result: 5` | Regression | All existing server tests (health, index, 404, prior op errors, divide) must still pass. ### UI (`test/ui.test.js`) | Case | Maps to | |------|---------| | Served HTML includes `data-key="%"` | AC4 (button) | | HTML/inline script maps `%` to `percent` (e.g. match on `'percent'` in `opMap` or operator handler) | AC4 (wiring) | | Existing `REQUIRED_KEYS` (other ops), `/api/calculate` fetch remain | Regression | Full suite: `npm test` must pass before push. ## Risks | Risk | Mitigation | |------|------------| | Wrong formula (e.g. `b * a / 100` vs `a * b / 100`, or `a / 100` only) | Task defines “a percent of b”; AC1 pins `50` and `8` → `4`; unit and HTTP tests lock semantics | | Operand order reversed in UI (`b` as percent, `a` as base) | Match existing binary-op pattern: first entered value is `a`, second is `b`; document flow in design; AC4 flow `50 % 8` → 4 | | Float rounding noise | AC uses exact values (`4`, `25`); use `assert.equal` / `deepEqual` like other ops | | Keypad layout regression | Keep all existing keys; only add/reposition `%` | | Breaking add / subtract / multiply / divide or validation | Run full test suite; extend rather than replace operator mapping | | `%` in regex or HTML test escaping | Escape `%` in `RegExp` for `REQUIRED_KEYS` loop like other special chars if needed (literal `%` in attribute is fine) | ## Implementation order 1. `lib/calculator.js` percent branch + unit tests in `test/calculator.test.js` 2. `test/server.test.js` for AC1–3 and regressions 3. `public/index.html` `%` button and operator mapping + `test/ui.test.js` 4. Full `npm test`, then push `aira/5-percentage` </details> Attachment: [plan-5-r1.md](https://aira-lab.cluster-dev.spkey.co/attachments/8e210eaa-26a9-4538-8df0-31fd6b219af3)
Collaborator

Aira · plan review

Plan pushed at 9ece0131; independent Dodik plan review started.

**Aira · plan review** Plan pushed at `9ece0131`; independent Dodik plan review started.
Collaborator

Aira · dodik-plan PASS on 9ece0131

The plan at 9ece013 covers percentage end to end and matches the code. Acceptance criteria 1–4 are concrete HTTP and page checks for a*b/100, bad input, and the % button flow 5 0 % 8 = showing 4. The design adds a percent branch in lib/calculator.js, leaves server.js validation unchanged, and wires a % key through the existing binary-operator path in public/index.html. The test plan proves those criteria in the module, over HTTP, and on the page, including zero operands and the error cases the task names, while existing operations stay covered by the current suite (34 tests passing).

Checks performed
  • Mapped the task requirements onto plan acceptance criteria 1–4, including 50% of 8 = 4 and 12.5% of 200 = 25
  • Read lib/calculator.js, server.js, and public/index.html at 9ece013 and confirmed the percent branch, unchanged 400 mapping, and % → pendingOp percent fit the current operator flow
  • Read test/calculator.test.js, test/server.test.js, and test/ui.test.js and checked that the new cases plus the existing regression tests cover each criterion, bad input, and the other operations
  • Ran npm test: 34 passed, 0 failed

Attachment: dodik-plan-9ece0131.json

**Aira · dodik-plan PASS on `9ece0131`** The plan at 9ece013 covers percentage end to end and matches the code. Acceptance criteria 1–4 are concrete HTTP and page checks for a*b/100, bad input, and the % button flow 5 0 % 8 = showing 4. The design adds a percent branch in lib/calculator.js, leaves server.js validation unchanged, and wires a % key through the existing binary-operator path in public/index.html. The test plan proves those criteria in the module, over HTTP, and on the page, including zero operands and the error cases the task names, while existing operations stay covered by the current suite (34 tests passing). <details><summary>Checks performed</summary> - Mapped the task requirements onto plan acceptance criteria 1–4, including 50% of 8 = 4 and 12.5% of 200 = 25 - Read lib/calculator.js, server.js, and public/index.html at 9ece013 and confirmed the percent branch, unchanged 400 mapping, and % → pendingOp percent fit the current operator flow - Read test/calculator.test.js, test/server.test.js, and test/ui.test.js and checked that the new cases plus the existing regression tests cover each criterion, bad input, and the other operations - Ran npm test: 34 passed, 0 failed </details> Attachment: [dodik-plan-9ece0131.json](https://aira-lab.cluster-dev.spkey.co/attachments/12c26a77-b2f9-4a92-8a49-d24643301bcc)
Collaborator

Aira · implementing

Plan approved by Dodik at 9ece0131. Implementation started.

**Aira · implementing** Plan approved by Dodik at `9ece0131`. Implementation started.
Collaborator

Aira · ci

Ready for review at 2d50abbf (PR #13). Waiting for CI.

Implemented percent in calculator and UI, added unit/server/UI tests covering all acceptance criteria; npm test 41/41 pass; pushed feat commit on aira/5-percentage.

**Aira · ci** Ready for review at `2d50abbf` (PR #13). Waiting for CI. Implemented percent in calculator and UI, added unit/server/UI tests covering all acceptance criteria; npm test 41/41 pass; pushed feat commit on aira/5-percentage.
Collaborator

Aira · CI passed on 2d50abbf

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

Aira · review

CI is green on 2d50abbf. Independent Dodik and code review started.

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

Aira · dodik PASS on 2d50abbf

Percentage is implemented as a percent of b (a * b / 100) in the calculator, the API, and a % button that follows the other binary operators. All 41 tests passed, the acceptance requests return 4 and 25, bad input still returns 400 with an error, and the 5 0 % 8 = flow displays 4. The diff is limited to that feature, its tests, and the issue plan; nothing was weakened or left as debug code.

Checks performed
  • Diff versus origin/main is only lib/calculator.js, public/index.html, test/calculator.test.js, test/server.test.js, test/ui.test.js, and docs/plans/issue-5.md
  • AC1: GET /api/calculate?a=50&b=8&op=percent returns 200 {"result":4}, covered by unit and server tests that throw unknown operation on origin/main
  • AC2: GET /api/calculate?a=12.5&b=200&op=percent returns 200 {"result":25}
  • AC3: non-numeric, empty, missing operand, missing op, and unknown op still return 400 with an error string; add and divide still succeed
  • AC4: served HTML has data-key="%" mapped to percent; executing the page script for 5, 0, %, 8, = fetches a=50&b=8&op=percent and sets the display to 4
  • npm test: 41 passed, 0 failed, 0 skipped, 0 todo
  • No weakened or removed assertions, no debug leftovers, and README does not document individual operations

Attachment: dodik-2d50abbf.json

**Aira · dodik PASS on `2d50abbf`** Percentage is implemented as a percent of b (a * b / 100) in the calculator, the API, and a % button that follows the other binary operators. All 41 tests passed, the acceptance requests return 4 and 25, bad input still returns 400 with an error, and the 5 0 % 8 = flow displays 4. The diff is limited to that feature, its tests, and the issue plan; nothing was weakened or left as debug code. <details><summary>Checks performed</summary> - Diff versus origin/main is only lib/calculator.js, public/index.html, test/calculator.test.js, test/server.test.js, test/ui.test.js, and docs/plans/issue-5.md - AC1: GET /api/calculate?a=50&b=8&op=percent returns 200 {"result":4}, covered by unit and server tests that throw unknown operation on origin/main - AC2: GET /api/calculate?a=12.5&b=200&op=percent returns 200 {"result":25} - AC3: non-numeric, empty, missing operand, missing op, and unknown op still return 400 with an error string; add and divide still succeed - AC4: served HTML has data-key="%" mapped to percent; executing the page script for 5, 0, %, 8, = fetches a=50&b=8&op=percent and sets the display to 4 - npm test: 41 passed, 0 failed, 0 skipped, 0 todo - No weakened or removed assertions, no debug leftovers, and README does not document individual operations </details> Attachment: [dodik-2d50abbf.json](https://aira-lab.cluster-dev.spkey.co/attachments/ca5bff19-5661-45c7-94b8-8151370d9137)
Collaborator

Aira · reviewer PASS on 2d50abbf

Issue #5 adds a correct percent operation (a * b / 100) with finite-result checks matching other ops, extends the UI with a % button mapped to pendingOp = 'percent', and adds focused unit, HTTP, and static UI tests. npm test passes all 41 tests; manual checks confirm negatives, zero operands, invalid empty b, and overflow handling. server.js is unchanged and existing validation and error responses apply to op=percent without regressions.

Checks performed
  • git diff origin/main...HEAD at 2d50abbf
  • lib/calculator.js percent branch and parseNumber reuse
  • public/index.html % button and opMap wiring
  • server.js calculate path unchanged
  • npm test (41 passing)
  • manual edge cases: negative operands, 1e200*1e200/100 overflow, empty b

Attachment: reviewer-2d50abbf.json

**Aira · reviewer PASS on `2d50abbf`** Issue #5 adds a correct `percent` operation (`a * b / 100`) with finite-result checks matching other ops, extends the UI with a `%` button mapped to `pendingOp = 'percent'`, and adds focused unit, HTTP, and static UI tests. `npm test` passes all 41 tests; manual checks confirm negatives, zero operands, invalid empty `b`, and overflow handling. `server.js` is unchanged and existing validation and error responses apply to `op=percent` without regressions. <details><summary>Checks performed</summary> - git diff origin/main...HEAD at 2d50abbf - lib/calculator.js percent branch and parseNumber reuse - public/index.html % button and opMap wiring - server.js calculate path unchanged - npm test (41 passing) - manual edge cases: negative operands, 1e200*1e200/100 overflow, empty b </details> Attachment: [reviewer-2d50abbf.json](https://aira-lab.cluster-dev.spkey.co/attachments/940dd68c-1058-4454-85ec-9605a985e8b2)
Collaborator

Aira · qa

Dodik and the reviewer passed on 2d50abbf. Preview deployed at http://127.0.0.1:35279; QA started.

**Aira · qa** Dodik and the reviewer passed on `2d50abbf`. Preview deployed at http://127.0.0.1:35279; QA started.
Collaborator

Aira · qa PASS on 2d50abbf

Health returns the preview commit. op=percent computes a percent of b (50 of 8 is 4, 12.5 of 200 is 25), including zero, negative, and decimal edges. Missing, empty, and non-numeric operands and unknown operations return 400 with an error string. Add, subtract, multiply, divide, and division by zero still behave as before. The served page includes a % button wired like the other binary operators, so 5, 0, %, 8, = calls op=percent and shows 4. npm test passed 41 tests covering the module, API, and page.

Checks performed
  • GET /health -> 200 {"ok":true,"sha":"2d50abbfb3860ae8b41e8278d2eed5c93f28bcb2"}
  • GET / -> 200 text/html with data-key="%" button; click handler maps % to op=percent the same way as + − × ÷, and = fetches /api/calculate then displays result
  • 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=0&b=100&op=percent -> 200 {"result":0}
  • GET /api/calculate?a=100&b=50&op=percent -> 200 {"result":50}
  • GET /api/calculate?a=200&b=50&op=percent -> 200 {"result":100}
  • GET /api/calculate?a=-25&b=80&op=percent -> 200 {"result":-20}
  • GET /api/calculate?a=33.3&b=10&op=percent -> 200 {"result":3.33}
  • GET /api/calculate?a=0&b=0&op=percent -> 200 {"result":0}
  • GET /api/calculate?a=1e2&b=50&op=percent -> 200 {"result":50}
  • GET /api/calculate?a=%2B50&b=8&op=percent -> 200 {"result":4}
  • GET /api/calculate?b=8&op=percent -> 400 {"error":"operand is required"}
  • GET /api/calculate?a=50&op=percent -> 400 {"error":"operand is required"}
  • GET /api/calculate?a=50&b=8 -> 400 {"error":"operation is required"}
  • GET /api/calculate -> 400 {"error":"operation is required"}
  • GET /api/calculate?a=&b=8&op=percent -> 400 {"error":"operand must be a number"}
  • GET /api/calculate?a=50&b=&op=percent -> 400 {"error":"operand must be a number"}
  • GET /api/calculate?a=50&b=8&op= -> 400 {"error":"operation is required"}
  • GET /api/calculate?a=foo&b=8&op=percent -> 400 {"error":"operand must be a number"}
  • GET /api/calculate?a=50&b=bar&op=percent -> 400 {"error":"operand must be a number"}
  • GET /api/calculate?a=Infinity&b=8&op=percent -> 400 {"error":"operand must be a number"}
  • GET /api/calculate?a=NaN&b=8&op=percent -> 400 {"error":"operand must be a number"}
  • GET /api/calculate?a=50&b=8&op=modulo -> 400 {"error":"unknown operation"}
  • GET /api/calculate?a=2&b=3&op=plus -> 400 {"error":"unknown operation"}
  • GET /api/calculate?a=2&b=3&op=add -> 200 {"result":5}
  • GET /api/calculate?a=10&b=4&op=subtract -> 200 {"result":6}
  • GET /api/calculate?a=3&b=10&op=subtract -> 200 {"result":-7}
  • GET /api/calculate?a=6&b=7&op=multiply -> 200 {"result":42}
  • GET /api/calculate?a=9&b=0&op=multiply -> 200 {"result":0}
  • GET /api/calculate?a=8&b=2&op=divide -> 200 {"result":4}
  • GET /api/calculate?a=8&b=0&op=divide -> 400 {"error":"division by zero"}
  • npm test -> 41 pass, 0 fail (module, API, and page, including percent)

Attachment: qa-2d50abbf.json

**Aira · qa PASS on `2d50abbf`** Health returns the preview commit. op=percent computes a percent of b (50 of 8 is 4, 12.5 of 200 is 25), including zero, negative, and decimal edges. Missing, empty, and non-numeric operands and unknown operations return 400 with an error string. Add, subtract, multiply, divide, and division by zero still behave as before. The served page includes a % button wired like the other binary operators, so 5, 0, %, 8, = calls op=percent and shows 4. npm test passed 41 tests covering the module, API, and page. <details><summary>Checks performed</summary> - GET /health -> 200 {"ok":true,"sha":"2d50abbfb3860ae8b41e8278d2eed5c93f28bcb2"} - GET / -> 200 text/html with data-key="%" button; click handler maps % to op=percent the same way as + − × ÷, and = fetches /api/calculate then displays result - 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=0&b=100&op=percent -> 200 {"result":0} - GET /api/calculate?a=100&b=50&op=percent -> 200 {"result":50} - GET /api/calculate?a=200&b=50&op=percent -> 200 {"result":100} - GET /api/calculate?a=-25&b=80&op=percent -> 200 {"result":-20} - GET /api/calculate?a=33.3&b=10&op=percent -> 200 {"result":3.33} - GET /api/calculate?a=0&b=0&op=percent -> 200 {"result":0} - GET /api/calculate?a=1e2&b=50&op=percent -> 200 {"result":50} - GET /api/calculate?a=%2B50&b=8&op=percent -> 200 {"result":4} - GET /api/calculate?b=8&op=percent -> 400 {"error":"operand is required"} - GET /api/calculate?a=50&op=percent -> 400 {"error":"operand is required"} - GET /api/calculate?a=50&b=8 -> 400 {"error":"operation is required"} - GET /api/calculate -> 400 {"error":"operation is required"} - GET /api/calculate?a=&b=8&op=percent -> 400 {"error":"operand must be a number"} - GET /api/calculate?a=50&b=&op=percent -> 400 {"error":"operand must be a number"} - GET /api/calculate?a=50&b=8&op= -> 400 {"error":"operation is required"} - GET /api/calculate?a=foo&b=8&op=percent -> 400 {"error":"operand must be a number"} - GET /api/calculate?a=50&b=bar&op=percent -> 400 {"error":"operand must be a number"} - GET /api/calculate?a=Infinity&b=8&op=percent -> 400 {"error":"operand must be a number"} - GET /api/calculate?a=NaN&b=8&op=percent -> 400 {"error":"operand must be a number"} - GET /api/calculate?a=50&b=8&op=modulo -> 400 {"error":"unknown operation"} - GET /api/calculate?a=2&b=3&op=plus -> 400 {"error":"unknown operation"} - GET /api/calculate?a=2&b=3&op=add -> 200 {"result":5} - GET /api/calculate?a=10&b=4&op=subtract -> 200 {"result":6} - GET /api/calculate?a=3&b=10&op=subtract -> 200 {"result":-7} - GET /api/calculate?a=6&b=7&op=multiply -> 200 {"result":42} - GET /api/calculate?a=9&b=0&op=multiply -> 200 {"result":0} - GET /api/calculate?a=8&b=2&op=divide -> 200 {"result":4} - GET /api/calculate?a=8&b=0&op=divide -> 400 {"error":"division by zero"} - npm test -> 41 pass, 0 fail (module, API, and page, including percent) </details> Attachment: [qa-2d50abbf.json](https://aira-lab.cluster-dev.spkey.co/attachments/3e48098e-5700-4592-91b0-dc23b6840796)
Collaborator

Aira · merging

QA passed on 2d50abbf. Merging.

**Aira · merging** QA passed on `2d50abbf`. Merging.
Collaborator

Aira · Merged PR #13

Merge commit 8fb581d67873b5da55f468b11804e6ae33fa4892 from reviewed head 2d50abbfb3860ae8b41e8278d2eed5c93f28bcb2.

Gate Verdict Summary
ci pass ci / test (pull_request)
dodik pass Percentage is implemented as a percent of b (a * b / 100) in the calculator, the API, and a % button that follows the other binary operators. All 41 tests passe
reviewer pass Issue #5 adds a correct percent operation (a * b / 100) with finite-result checks matching other ops, extends the UI with a % button mapped to `pendingOp
qa pass Health returns the preview commit. op=percent computes a percent of b (50 of 8 is 4, 12.5 of 200 is 25), including zero, negative, and decimal edges. Missing, e
**Aira · Merged PR #13** Merge commit `8fb581d67873b5da55f468b11804e6ae33fa4892` from reviewed head `2d50abbfb3860ae8b41e8278d2eed5c93f28bcb2`. | Gate | Verdict | Summary | |---|---|---| | ci | pass | ci / test (pull_request) | | dodik | pass | Percentage is implemented as a percent of b (a * b / 100) in the calculator, the API, and a % button that follows the other binary operators. All 41 tests passe | | reviewer | pass | Issue #5 adds a correct `percent` operation (`a * b / 100`) with finite-result checks matching other ops, extends the UI with a `%` button mapped to `pendingOp | | qa | pass | Health returns the preview commit. op=percent computes a percent of b (50 of 8 is 4, 12.5 of 200 is 25), including zero, negative, and decimal edges. Missing, e |
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-3#5
No description provided.