Skip to content

fix: pass all failing tests (implement missing functions + fix edge cases) - #344

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2188-1789575564
Open

stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier1-2188-1789575564

Conversation

@stooit

@stooit stooit commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 16 failing tests across 5 files. Test suite now: 60 pass / 0 fail, tsc --noEmit clean. No test files modified, no dependencies added.

Changes by file

  • src/calculator.ts — divide throws Error("Division by zero") when divisor is 0 (was silently returning Infinity/NaN).
  • src/string-utils.ts
    • wordCount — trims and splits on /\s+/ so runs of whitespace no longer count as extra words.
    • truncate — implemented per the TODO spec: returns unchanged if str.length <= maxLength; otherwise reserves 3 chars for "...", cuts to budget, and backs up to the last word boundary. Falls back to a hard cut when the first word exceeds the budget.
  • src/task-manager.ts — implemented stubbed methods: remove (returns delete boolean), update (returns false for unknown id; applies only provided keys), sortBy (priority high→medium→low; createdAt oldest first).
  • src/date-utils.ts — diffDays uses Math.round instead of Math.floor, so 36h now reads "2 days ago".
  • src/validator.ts — isEmail accepts long TLDs ({2,}); isUrl accepts URLs with a port.

Assumptions & notes

  • divide throwing is a behavioural change for any caller that relied on Infinity — driven by the test.
  • isUrl now accepting arbitrary ports widens accepted input; if it ever guards outbound requests, port-restriction may be worth revisiting (SSRF surface). Out of scope for these tests.
  • createdAt sort relies on spec-stable Array.prototype.sort so same-ms ties keep insertion order.

Testing

  • bun test — 60 pass / 0 fail
  • tsc --noEmit — clean

…ests

- calculator.divide: throw on division by zero
- string-utils.wordCount: collapse consecutive whitespace
- string-utils.truncate: implement word-boundary truncation with ellipsis
- task-manager: implement remove, update, and sortBy
- date-utils: round diffDays instead of floor (36h -> 2 days)
- validator: accept long TLDs (isEmail) and ports (isUrl)
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