Skip to content

Add factorial calculation utility service#70

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/calculate-factorial-of-number
Draft

Add factorial calculation utility service#70
Copilot wants to merge 2 commits intomainfrom
copilot/calculate-factorial-of-number

Conversation

Copy link
Contributor

Copilot AI commented Mar 25, 2026

Adds a general-purpose MathService to support factorial computation of non-negative integers.

New surface area

  • IMathService — interface with long CalculateFactorial(int n)
  • MathService — iterative implementation; supports inputs 0–20 (full long-safe range)
    • n < 0ArgumentOutOfRangeException
    • n > 20OverflowException (21! exceeds Int64.MaxValue)

Usage

IMathService math = new MathService();

math.CalculateFactorial(0);   // 1
math.CalculateFactorial(10);  // 3628800
math.CalculateFactorial(20);  // 2432902008176640000
math.CalculateFactorial(-1);  // throws ArgumentOutOfRangeException
math.CalculateFactorial(21);  // throws OverflowException

Tests

15 xUnit tests in MathServiceTests covering base cases (0, 1), a parameterised sweep of known values up to 20!, and both error paths.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Add function to calculate factorial of a number Add factorial calculation utility service Mar 25, 2026
Copilot AI requested a review from kavyashri-as March 25, 2026 05:35
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.

2 participants