Created
January 10, 2017 03:39
-
-
Save raelyard/5fd9e961fa74c60e10e9f23b5a50c8df to your computer and use it in GitHub Desktop.
This file contains 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
public class FactorialTest | |
{ | |
[Fact] | |
public void Factorial0() | |
{ | |
Factorial(0).ShouldEqual(1); | |
} | |
[Fact] | |
public void Factorial1() | |
{ | |
Factorial(1).ShouldEqual(1); | |
} | |
[Fact] | |
public void Factorial2() | |
{ | |
Factorial(2).ShouldEqual(2); | |
} | |
[Fact] | |
public void Factorial3() | |
{ | |
Factorial(3).ShouldEqual(6); | |
} | |
[Fact] | |
public void Factorial4() | |
{ | |
Factorial(4).ShouldEqual(24); | |
} | |
[Fact] | |
public void Factorial5() | |
{ | |
Factorial(5).ShouldEqual(120); | |
} | |
[Fact] | |
public void Factorial100() | |
{ | |
Factorial(100) | |
.ShouldEqual( | |
BigInteger.Parse( | |
"93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000")); | |
} | |
public BigInteger Factorial(BigInteger argument) | |
{ | |
return argument > 1 ? argument*Factorial(--argument) : 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment