Write unit tests for a given piece of code.
Asked in the Onsite skills test stage. Part of the Java skills test alongside design patterns theory and a simple tree question.
Test the following function using a standard unit-testing framework. Cover normal behavior, the \$100 threshold, priority handling, and invalid negative amounts.
def calculate_fee(amount, is_priority):
if amount < 0:
raise ValueError("amount cannot be negative")
fee = 0 if amount >= 100 else 5
if is_priority:
fee += 10
return fee
Your tests should assert returned values and verify that negative amounts raise ValueError. Include boundary and representative cases.
amount is an integer or floating-point numberis_priority is a booleanValueErrordef test_calculate_fee(amount, is_priority):