Problem Statement
When financial calculations are incorrect, users lose trust and money can be misallocated. Small errors in splitting bills or rounding can cause disputes and damage the app's reputation.
This diagram shows how developers write code that includes financial logic, which is then verified by automated tests producing test results to ensure correctness.
### Before: No tests for financial logic class Expense: def __init__(self, total, participants): self.total = total self.participants = participants def split(self): return self.total / len(self.participants) ### After: Adding tests to verify splitting logic import unittest class Expense: def __init__(self, total, participants): self.total = total self.participants = participants def split(self): # Round to 2 decimals for currency return round(self.total / len(self.participants), 2) class TestExpense(unittest.TestCase): def test_split_even(self): expense = Expense(100, ['A', 'B', 'C', 'D']) self.assertEqual(expense.split(), 25.00) def test_split_rounding(self): expense = Expense(100, ['A', 'B', 'C']) self.assertEqual(expense.split(), 33.33) if __name__ == '__main__': unittest.main()