Skip to content

fix: implement missing utilities and fix edge-case bugs (all tests green) - #349

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2169-1790093959
Open

stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2169-1790093959

Conversation

@stooit

@stooit stooit commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all failing tests in the utility library. The suite went from 44 pass / 16 fail to 60 pass / 0 fail, tsc --noEmit exits clean, and only the five source files were touched — no test files modified, no dependencies added.

Changes

  • src/calculator.ts — divide now throws Error("Division by zero") when b === 0 (also catches -0) instead of silently returning Infinity.
  • src/string-utils.ts
    • wordCount — split on /\s+/ against the trimmed string so runs of consecutive whitespace (and tabs/newlines) collapse; fixes "hello world" returning 3.
    • truncate — implemented to the documented contract: unchanged when str.length <= maxLength; otherwise reserves 3 chars for "...", snaps to the last word boundary, result always <= maxLength. Negative/small-limit guard clamped with Math.max(0, maxLength).
  • src/task-manager.ts — implemented the three stubbed methods: remove (returns delete boolean), update (partial update; description clearable via "description" in changes), and sortBy (priority / status / createdAt, stable for ties).
  • src/date-utils.ts — diffDays now does Math.round(Math.abs(diffHours) / 24), matching the abs-then-round convention of the adjacent branches. Removes the off-by-one and the past/future asymmetry.
  • src/validator.ts
    • isEmail — accepts arbitrary subdomain depth and long TLDs, still rejects whitespace / missing @ / malformed labels.
    • isUrl — dropped the empty-port condition that rejected http://localhost:3000; still restricted to http/https, requires a non-empty hostname.

Verification

  • bun test -> 60 pass, 0 fail
  • tsc --noEmit -> exit 0
  • Independent review pass returned a ship verdict; its priority finding (signed-rounding asymmetry) plus two safe hardening items were applied before commit.

Assumptions

  • Implemented each function to the contract expressed by its tests and in-source TODO:/BUG: comments.
  • divide(x, 0) throwing is an intentional breaking change vs. the old Infinity behaviour — pinned by the test.
  • isEmail is a format-level check, not authoritative validation.

Follow-ups (non-blocking)

  • isEmail now silently rejects underscores and non-ASCII/IDN domains (previously accepted) — worth a docstring note.
  • A cleared description retains the key with undefined; delete task.description would be cleaner if tasks are ever persisted.

Make all 60 tests pass (was 44 pass / 16 fail) with no test-file or
dependency changes.

- calculator: divide now throws on division by zero instead of returning Infinity
- string-utils: implement truncate (word-boundary, ellipsis counts toward
  maxLength, negative-limit safe); fix wordCount to collapse consecutive whitespace
- task-manager: implement remove, update (partial, description-clearable), and sortBy
- date-utils: fix diffDays rounding (abs before round) to remove off-by-one and
  past/future asymmetry
- validator: fix isEmail (arbitrary subdomain depth / long TLDs) and isUrl
  (allow explicit ports like localhost:3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant