|
| 1 | +"""Test file with medium/low severity issues only (no HIGH severity).""" |
| 2 | + |
| 3 | + |
| 4 | +def find_duplicates(items): |
| 5 | + """Find duplicate items in a list. |
| 6 | +
|
| 7 | + Medium severity: O(n²) algorithm when O(n) with set is possible. |
| 8 | + """ |
| 9 | + duplicates = [] |
| 10 | + for i in range(len(items)): |
| 11 | + for j in range(i + 1, len(items)): |
| 12 | + if items[i] == items[j] and items[i] not in duplicates: |
| 13 | + duplicates.append(items[i]) |
| 14 | + return duplicates |
| 15 | + |
| 16 | + |
| 17 | +def calculate_discount(price, discount_percent): |
| 18 | + """Calculate discounted price. |
| 19 | +
|
| 20 | + Low severity: Uses magic number instead of named constant. |
| 21 | + """ |
| 22 | + if discount_percent > 50: # Magic number - what does 50 represent? |
| 23 | + discount_percent = 50 |
| 24 | + return price * (1 - discount_percent / 100) |
| 25 | + |
| 26 | + |
| 27 | +def process_data(data): |
| 28 | + """Process data and return result. |
| 29 | +
|
| 30 | + Low severity: Doesn't handle empty input gracefully. |
| 31 | + """ |
| 32 | + total = 0 |
| 33 | + for item in data: |
| 34 | + total += item["value"] # Will crash if data is empty or item has no "value" |
| 35 | + return total / len(data) # Division by zero if data is empty |
| 36 | + |
| 37 | + |
| 38 | +def format_user_info(user): |
| 39 | + """Format user information for display. |
| 40 | +
|
| 41 | + Low severity: Unused variable. |
| 42 | + """ |
| 43 | + unused_temp = user.get("temp", "default") # Never used |
| 44 | + name = user.get("name", "Unknown") |
| 45 | + email = user.get("email", "N/A") |
| 46 | + return f"{name} <{email}>" |
0 commit comments