Skip to content

Anjali Dewangan — R51-T048: Cover the failure behavior of factorial (factorial.js) [src/algorithms/math/factorial] #48

Open

Description

@ankushbisht01

Student: Anjali Dewangan

Task: R51-T048 · 8 of 10
Repository: https://github.com/S-AI-Projects/javascript-algorithms
Assigned working branch: student/e26b07f0661

Goal

Work on src/algorithms/math/factorial/factorial.js. Exercise a documented failure or absent-result branch of factorial. Where the contract is total, use its valid empty/missing-result case instead of inventing an exception. Fixture: Use 0, 1, 2 and 5, expecting 1, 1, 2 and 120 when the documented domain includes zero.

Steps

  1. Read src/algorithms/math/factorial/factorial.js, especially factorial near line 5. Record its public inputs, result, mutation behavior and any external dependencies before changing it.
  2. Locate the actual return, raise, rejection or fallback branch in the source and construct the smallest input reaching it.
  3. Assert the intended exception/sentinel and verify that caller-owned state remains valid afterwards; include a successful call after the failure.
  4. Implement work/R51-T048/check.py as a focused runner that executes the new checks and propagates failures. Native check to incorporate: run the repository test script in non-watch mode after installing from its lockfile; for browser-only code use a browser test instead of plain Node. Record the actual command and nonzero test count.
  5. Create the checks specified below and run python3 work/R51-T048/check.py. Save inputs, expected versus actual results and tool versions in work/R51-T048/; a check must exit non-zero when an assertion fails.
  6. Commit the repository change on branch R51-T048; prepare a PR to the organisation fork explaining the result and linking the checks. Keep each task independently reviewable. Remove work/R51-T048/ from a later upstream branch.

Done when

☐ The checked behavior is tied to factorial in src/algorithms/math/factorial/factorial.js; every assertion has an explicit expected value.
☐ Use 0, 1, 2 and 5, expecting 1, 1, 2 and 120 when the documented domain includes zero.
☐ Existing supported behavior and the public interface are preserved unless a failing regression demonstrates and documents a defect.
☐ The tested branch is named by source line and the input actually reaches it.
☐ An ordinary valid call still succeeds after the failure case.

Additional task guidance

Additional curated task guidance

Item:
src/algorithms/math/factorial

Task type:
Failure-path coverage

Code change (goes into the PR):
src/algorithms/math/factorial/factorial.js: add focused tests and a short explanation of the chosen failure/empty-result path. Repair error handling only if the regression proves it violates the contract.

Automated check:
python3 work/R51-T048/check.py

Prerequisites:
Node matching project CI, the project lockfile dependencies, and Python 3.

Upstream PR rules:
Keep the contribution scoped to the named item and follow the linked contribution instructions and repository CI. Submit coursework to the organisation fork first; keep work/ evidence out of any later upstream PR. Upstream acceptance is not a grading requirement. Policy: https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/CONTRIBUTING.md

Source (pinned):
https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/algorithms/math/factorial/factorial.js#L5

Change:
Replaces the shared task template with an item-specific contribution brief.

PR destination:
Upstream candidate after review

Submission checklist

  • Complete this task and its checks.
  • Add the required evidence and link your pull request here.
  • Select this S-AI-Projects fork as the PR base repository.
  • Request instructor review.

Keep this PR focused on this task. Do not submit assignment PRs to the upstream repository.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions