Computing a value recursively: Factorial The goal for this exercise

advertisement
Computing a value recursively: Factorial
The goal for this exercise is to practice writing (increasingly complex) recursive
code, this time using a classic example of recursion.
For this exercise, you need to implement the Factorial method in the
provided RecursiveMethods class.
This class should be found in the Student_Answers.cs file in a project
named something like 03_PCE_StudentCode. You need to add code to the
Factorial method, which will compute Factorial(N). Factorial is defined as:
Factorial(N) = N * Factorial(N-1)
Factorial(0) = 1
Your function should have a single parameter, n, and return the Factorial
of n. Any value of n less than 0 should simply return 0;
Once you’ve done this, make sure that all the tests in the
NUnit_Tests_Factorial_Recursive class pass.
What you need to do for this exercise:
1. Implement Factorial, as described above
2. Once you’ve completed the above task, you should run the tests in the
NUnit_Tests_Factorial_Recursive class. They should all pass at this point,
and if not, then you should fix your program so that those tests do pass. You
can run the tests using the NUnit support in the provided starter project. You
should feel free to supplement that code with your own test cases if you wish,
but you are neither required nor expected to.
Download