public void Factorial1() { int number = 1; int expect = 1; int res = FactorialSolver.Factorial(number); Assert.Equal(expect, res); }
public void Factorial9() { int number = 9; int expect = 362880; int res = FactorialSolver.Factorial(number); Assert.Equal(expect, res); }
public void Factorial8() { int number = 8; int expect = 40320; int res = FactorialSolver.Factorial(number); Assert.Equal(expect, res); }
public void Factorial5() { int number = 5; int expect = 120; int res = FactorialSolver.FactorialWhileLoop(number); Assert.Equal(expect, res); }
public void Factorial5() { int number = 5; int expect = 120; int res = FactorialSolver.FactorialRecursion(number); Assert.Equal(expect, res); }
public string Parse(string input) { var factorials = new Regex("[0-9]+!"); var matches = factorials.Matches(input); if (matches.Count == 0) { return(input); } foreach (Match match in matches) { var val = match.Value; var num = int.Parse(val.Substring(0, val.Length - 1)); var result = FactorialSolver.Solve(num); input = input.Replace(val, result.ToString()); } return(input); }