fix: repair all failing tests in utility library - #300
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide now throws on zero divisor instead of returning Infinity - string-utils: implement truncate; wordCount collapses consecutive whitespace - task-manager: implement remove/update/sortBy methods - date-utils: formatRelative uses Math.round to fix off-by-one at day boundaries - validator: isEmail allows long TLDs (.museum); isUrl allows ports
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 16 failing tests across the 5 utility modules. Result: 60 pass / 0 fail (
bun test),tsc --noEmitclean. No test files modified, no dependencies added.Changes
src/calculator.ts—dividethrows on a zero divisor instead of returningInfinity(b === 0also catches-0).src/string-utils.ts— implementedtruncate(returns unchanged within limit; reserves 3 chars for ellipsis; cuts at last word boundary within budget, hard-cuts when no space ormaxLength <= 3, output length never exceedsmaxLength).wordCountnow splits on/\s+/so consecutive whitespace collapses.src/task-manager.ts— implementedremove(bool viaMap.delete),update(returnsfalsefor unknown id; applies only fields present inchanges), andsortBy(priorityhigh>medium>low,createdAtoldest-first; sorts a copy, does not mutate state).src/date-utils.ts—formatRelativeday calc usesMath.roundinstead ofMath.floor, fixing the off-by-one so 36h → "2 days ago".src/validator.ts—isEmailTLD quantifier relaxed{2,4}→{2,}(allows.museum);isUrlno longer requires an empty port, sohttp://localhost:3000validates.Verification
bun test: 60 pass / 0 fail, stable across repeated runstsc --noEmit: cleanAssumptions & notes (non-blocking)
sortBy("createdAt")includes a numeric-id tiebreaker for determinism when two tasks land in the same millisecond. Relies onadd()generating numeric string ids.sortBystatus ordering (in_progress < pending < completed) is unspecified by tests — a reasonable default chosen for completeness.updateuses!== undefinedchecks (patch semantics), so optional fields can't be cleared toundefinedvia a partial update.isEmailremains a permissive shape check, not RFC 5322 validation — consistent with the test expectations.