import unittest
# Function to test
def calculate_discount(customer_type, amount):
if customer_type == 'regular':
return amount * 0.9 # 10% discount
elif customer_type == 'vip':
return amount * 0.8 # 20% discount
else:
return amount # no discount
class TestCalculateDiscount(unittest.TestCase):
def test_regular_customer(self):
self.assertEqual(calculate_discount('regular', 100), 90)
def test_vip_customer(self):
self.assertEqual(calculate_discount('vip', 100), 80)
def test_unknown_customer(self):
self.assertEqual(calculate_discount('guest', 100), 100)
if __name__ == '__main__':
unittest.main()This test script uses Python's unittest framework to check the calculate_discount function.
Each test method checks a different internal branch of the function: 'regular', 'vip', and unknown customer types.
Assertions verify the output matches expected discounts, ensuring the internal logic is tested.
This approach shows white-box testing by directly examining and validating the code's internal decision paths.