Vidyavardhini's College of Engineering & Technology Department of Computer Engineering Academic Year:2024-25
Vidyavardhini's College of Engineering & Technology Department of Computer Engineering Academic Year:2024-25
Aim: Develop test cases for white Box testing for a given code
def factorial(n):
if n < 0:
raise ValueError("Negative numbers are not allowed.")
elif n == 0:
return 1
else:
result = 1
for i in range(1, n + 1):
result *= i
return result
• Input: n = -5
• Expected Output: Raise ValueError
• Reason: To check that the function correctly handles invalid negative input.
• Input: n = 0
• Expected Output: 1
• Reason: To verify that the factorial of zero returns 1, which is the base case.
• Input: n = 1
• Expected Output: 1
• Reason: To check that the factorial of 1 returns 1.
• Input: n = 5
• Expected Output: 120
• Reason: To validate the correct calculation of factorial for a small positive integer.
• Input: n = 10
Vidyavardhini's College of Engineering & Technology
Department of Computer Engineering
Academic Year:2024-25
• Input: n = 2
• Expected Output: 2
• Reason: To check the output for the smallest even positive integer.
• Input: n = 20
• Expected Output: 2432902008176640000
• Reason: To test performance and correctness with larger integers, observing if any
overflow or performance issues occur.
Conclusion
These test cases should cover various scenarios and edge cases for the given factorial
function. In actual practice, you'd automate these tests and use a testing framework like
unittest or pytest to facilitate testing. If you have a specific piece of code in mind, feel
free to share it, and I can help you develop tailored test cases!