fix: resolve all failing tests in utility library#216
Open
stooit wants to merge 1 commit into
Open
Conversation
- calculator: divide() throws on division by zero instead of returning Infinity - string-utils: fix wordCount whitespace handling and implement truncate - task-manager: implement remove/update/getByPriority/getOverdue - date-utils: fix off-by-one in formatRelative (round instead of floor) - validator: accept URLs with ports and longer email TLDs
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
Fixed 16 failing tests across 5 utility modules. All 60 tests now pass (0 fail), with no changes to test files and no new dependencies.
Changes
src/calculator.ts—divide()now throwsError("Division by zero")when the divisor is0instead of silently returningInfinity.src/string-utils.ts—wordCount()now trims and splits on/\s+/so consecutive spaces don't produce empty tokens;truncate()implemented.src/task-manager.ts— implemented the missing/incompleteTaskManagermethods (remove, update, query by priority, overdue).src/date-utils.ts— fixed off-by-one informatRelative(Math.floor→Math.round), so e.g. 36 hours ago renders as "2 days ago".src/validator.ts—isUrl()accepts URLs with ports (usesnew URL()with no port restriction);isEmail()accepts TLDs of length ≥ 2 via[a-zA-Z]{2,}.Verification
bun test→ 60 pass, 0 fail (70 assertions).isUrl/isEmailimplementations as weakened, but a verification pass against the actual source confirmed those were false positives — the live code uses the robustnew URL()parser and a correct TLD bound.Assumptions