--- epic: 5 story: 5.4 title: "Section Aggregators" status: draft --- ## Epic 5 — Variables, Line References & Aggregators **Goal:** Transform the notepad into a lightweight computational document. ### Story 5.4: Section Aggregators As a **CalcPad user**, I want to use aggregation keywords like `sum`, `total`, `average`, `min`, `max`, and `count` to compute over a section of lines, So that I can quickly summarize a group of related values without manually writing out each reference. **Acceptance Criteria:** **Given** lines 1–4 contain numeric values `10`, `20`, `30`, `40` and line 5 is empty **When** the user writes `sum` on line 5 (or after the group) **Then** the result is `100` (sum of lines 1–4) **Given** lines 1–4 contain numeric values and line 5 is a heading `## Monthly Costs` **When** the user writes `total` immediately after lines 6–9 (which contain values under that heading) **Then** `total` sums only lines 6–9 (the section bounded by the heading above and the aggregator line) **Given** a section with values `10`, `20`, `30` **When** the user writes `average` (or `avg`) at the end of the section **Then** the result is `20` **Given** a section with values `5`, `12`, `3`, `8` **When** the user writes `min` at the end of the section **Then** the result is `3` **Given** a section with values `5`, `12`, `3`, `8` **When** the user writes `max` at the end of the section **Then** the result is `12` **Given** a section with values `5`, `12`, `3`, `8` **When** the user writes `count` at the end of the section **Then** the result is `4` (number of lines with numeric results) **Given** a section contains a mix of numeric lines and comment lines **When** an aggregator is applied **Then** only lines with numeric results are included in the aggregation (comments and blank lines are skipped) **Given** an empty section (heading immediately followed by another heading or end-of-document) **When** the user writes `sum` **Then** the result is `0` (or an appropriate indication that there are no values to aggregate)