0% found this document useful (0 votes)
14 views2 pages

Vidyavardhini's College of Engineering & Technology Department of Computer Engineering Academic Year:2024-25

Uploaded by

bramhatechnocrat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Vidyavardhini's College of Engineering & Technology Department of Computer Engineering Academic Year:2024-25

Uploaded by

bramhatechnocrat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

White-Box Test Cases

Test Case 1: Test Negative Input

• Input: n = -5
• Expected Output: Raise ValueError
• Reason: To check that the function correctly handles invalid negative input.

Test Case 2: Test Zero Input

• Input: n = 0
• Expected Output: 1
• Reason: To verify that the factorial of zero returns 1, which is the base case.

Test Case 3: Test Small Positive Input

• Input: n = 1
• Expected Output: 1
• Reason: To check that the factorial of 1 returns 1.

Test Case 4: Test Medium Positive Input

• Input: n = 5
• Expected Output: 120
• Reason: To validate the correct calculation of factorial for a small positive integer.

Test Case 5: Test Large Positive Input

• Input: n = 10
Vidyavardhini's College of Engineering & Technology
Department of Computer Engineering
Academic Year:2024-25

• Expected Output: 3628800


• Reason: To ensure that the function can handle larger inputs correctly.

Test Case 6: Test Boundary Condition

• Input: n = 2
• Expected Output: 2
• Reason: To check the output for the smallest even positive integer.

Test Case 7: Test Performance with Large Input

• Input: n = 20
• Expected Output: 2432902008176640000
• Reason: To test performance and correctness with larger integers, observing if any
overflow or performance issues occur.

Code Coverage Considerations

• Ensure that all branches in the code are tested:


o The negative input branch (if n < 0)
o The base case (elif n == 0)
o The loop for positive integers.

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!

You might also like