import pytest from dataset.problem_19.buggy import calculate_employee_bonus def test_calculate_employee_bonus(): employees = [ {'id': 1, 'role': 'engineering', 'base_salary': 100000, 'rating': 4}, {'id': 2, 'role': 'sales', 'base_salary': '80000', 'rating': 3}, {'id': 3, 'role': 'hr', 'base_salary': 60000, 'rating': 2}, {'id': 4, 'role': 'unknown', 'base_salary': 50000, 'rating': 5} ] metrics = { 'company_multiplier': 1.2, 'department_multipliers': { 'engineering': 1.5, 'sales': 1.2, 'hr': 1.0 } } # Original dicts should not be modified orig_employees = [dict(e) for e in employees] results = calculate_employee_bonus(employees, metrics) # Check if original was modified assert employees == orig_employees, "Original list was mutated" # Check results format assert len(results) == 4 for r in results: assert 'id' in r assert 'bonus' in r assert 'role' not in r # Should only contain id and bonus # Check values # Emp 1: 100000 * 0.1 * 1.5 * 1.2 = 18000 assert results[0]['bonus'] == 18000 # Emp 2: 80000 * 0.05 * 1.2 * 1.2 = 5760 (string salary handling) assert results[1]['bonus'] == 5760 # Emp 3: 0 bonus due to rating 2 assert results[2]['bonus'] == 0 # Emp 4: unknown role falls back to 1.0 multiplier # 50000 * 0.1 * 1.0 * 1.2 = 6000 assert results[3]['bonus'] == 6000