Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes all failing tests in the utility library. The suite went from 44 pass / 16 fail to 60 pass / 0 fail,
tsc --noEmitexits clean, and only the five source files were touched — no test files modified, no dependencies added.Changes
src/calculator.ts—dividenow throwsError("Division by zero")whenb === 0(also catches-0) instead of silently returningInfinity.src/string-utils.tswordCount— 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 whenstr.length <= maxLength; otherwise reserves 3 chars for"...", snaps to the last word boundary, result always<= maxLength. Negative/small-limit guard clamped withMath.max(0, maxLength).src/task-manager.ts— implemented the three stubbed methods:remove(returns delete boolean),update(partial update;descriptionclearable via"description" in changes), andsortBy(priority / status / createdAt, stable for ties).src/date-utils.ts—diffDaysnow doesMath.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.tsisEmail— accepts arbitrary subdomain depth and long TLDs, still rejects whitespace / missing@/ malformed labels.isUrl— dropped the empty-port condition that rejectedhttp://localhost:3000; still restricted to http/https, requires a non-empty hostname.Verification
bun test-> 60 pass, 0 failtsc --noEmit-> exit 0Assumptions
TODO:/BUG:comments.divide(x, 0)throwing is an intentional breaking change vs. the oldInfinitybehaviour — pinned by the test.isEmailis a format-level check, not authoritative validation.Follow-ups (non-blocking)
isEmailnow silently rejects underscores and non-ASCII/IDN domains (previously accepted) — worth a docstring note.descriptionretains the key withundefined;delete task.descriptionwould be cleaner if tasks are ever persisted.