Question: Using the definition for factorial from here and boundary analysis as described in the class video, write the set of Test Cases to test the

Using the definition for factorial from here and boundary analysis as described in the class video, write the set of Test Cases to test the C# function
int Factorial(int n)
which takes an integer n and returns the factorial if such number exists and can be calculated and throws ArgumentOutOfRangeException if the factorial doesn't exist or can't be calculated.
Name your Test Cases TestMethodX where X is a counter starting from 1.
what i have so far, do not change or put any code outside of the start code and end code comments.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
[TestClass]
public partial class UnitTests
{
[TestMethod]
public void TestMethod1()
{
Assert.AreEqual(1, Factorial(0));
}
//Your code starts here
// TestMethod2: Factorial of -1, should throw ArgumentOutOfRangeException
// TestMethod2: Factorial of -1, should throw ArgumentOutOfRangeException
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestMethod2()
{
ComputeFactorial(-1);
}
// TestMethod3: Factorial of 1, should return 1
[TestMethod]
public void TestMethod3()
{
Assert.AreEqual(1, ComputeFactorial(1));
}
// TestMethod4: Factorial of 5, should return 120
[TestMethod]
public void TestMethod4()
{
Assert.AreEqual(120, ComputeFactorial(5));
}
// TestMethod5: Factorial of 12, largest valid value, should return 479001600
[TestMethod]
public void TestMethod5()
{
Assert.AreEqual(479001600, ComputeFactorial(12));
}
// TestMethod6: Factorial of 13, should throw ArgumentOutOfRangeException (overflow)
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestMethod6()
{
ComputeFactorial(13);
}
// TestMethod7: Factorial of int.MinValue, should throw ArgumentOutOfRangeException
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestMethod7()
{
ComputeFactorial(int.MinValue);
}
// TestMethod8: Factorial of 11, valid upper boundary, should return 39916800
[TestMethod]
public void TestMethod8()
{
Assert.AreEqual(39916800, ComputeFactorial(11));
}
// TestMethod9: Factorial of 2, small valid value, should return 2
[TestMethod]
public void TestMethod9()
{
Assert.AreEqual(2, ComputeFactorial(2));
}
// TestMethod10: Factorial of 14, should throw ArgumentOutOfRangeException (overflow test for larger values)
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestMethod10()
{
ComputeFactorial(14);
}
// Factorial function implementation
public int ComputeFactorial(int n)
{
if (n <0|| n >12)
{
throw new ArgumentOutOfRangeException();
}
if (n ==0) return 1;
int result =1;
for (int i =1; i <= n; i++)
{
result *= i;
}
return result;
}
//Your code ends here
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!