Question: Feedback ( Succeeded ) ( 5 / 5 points ) : Passed TestMethod 1 ( Succeeded ) ( 5 / 5 points ) : Passed

Feedback
(Succeeded)(5/5 points): Passed TestMethod1
(Succeeded)(5/5 points): Passed TestMethod2
(Succeeded)(5/5 points): Passed TestMethod3
(Succeeded)(5/5 points): Passed TestMethod4
(Succeeded)(5/5 points): Passed TestMethod5
(Succeeded)(5/5 points): Passed TestMethod6
(Succeeded)(5/5 points): Passed TestMethod7
(Succeeded)(5/5 points): Passed TestMethod8
(Succeeded)(5/5 points): Passed TestMethod9
(Succeeded)(5/5 points): Passed TestMethod10
(Failed)(0/50 points): Passed zTestExpected
ASSISTANT HINT #2985 for 11
8/26/202421:59
Make sure to test all the boundary cases, including the smallest and largest valid values, the smallest and largest invalid values, and the values that are just outside the valid range. Also, make sure to name your test cases as TestMethodX where X is a counter starting from 1. it was incorrect and i cannot change anything outside of the comments including test case method 1
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.
code: 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
// TestMethod 2: Factorial of -1, should throw ArgumentOutOfRangeException
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestMethod2()
{
ComputeFactorial(-1);
}
// TestMethod 3: Factorial of 1, should return 1
[TestMethod]
public void TestMethod3()
{
Assert.AreEqual(1, ComputeFactorial(1));
}
// TestMethod 4: Factorial of 5, should return 120
[TestMethod]
public void TestMethod4()
{
Assert.AreEqual(120, ComputeFactorial(5));
}
// TestMethod 5: Factorial of 12, largest valid value, should return 479001600
[TestMethod]
public void TestMethod5()
{
Assert.AreEqual(479001600, ComputeFactorial(12));
}
// TestMethod 6: Factorial of 13, should throw ArgumentOutOfRangeException (overflow)
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestMethod6()
{
ComputeFactorial(13);
}
// TestMethod 7: Factorial of int.MinValue, should throw ArgumentOutOfRangeException
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestMethod7()
{
ComputeFactorial(int.MinValue);
}
// TestMethod 8: Factorial of 11, valid upper boundary, should return 39916800
[TestMethod]
public void TestMethod8()
{
Assert.AreEqual(39916800, ComputeFactorial(11));
}
// TestMethod 9: Factorial of 2, small valid value, should return 2
[TestMethod]
public void TestMethod9()
{
Assert.AreEqual(2, ComputeFactorial(2));
}
// TestMethod 10: 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!