Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import os # unused import β€” LINTING bug on line 1

def add(a, b):
return a + b
return a + b
4 changes: 2 additions & 2 deletions src/validator.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def validate(x) # missing colon β€” SYNTAX bug on line 1
return x > 0
def validate(x):
return x > 0
139 changes: 60 additions & 79 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,60 @@
import os
import sys
import json
import math
import random

# ─── Bug 1: LINTING β€” unused imports (os, sys, json, random) ─────────────────

# ─── Bug 2: INDENTATION error ────────────────────────────────────────────────
def calculate_area(length, width):
area = length * width
return area


# ─── Bug 3: SYNTAX error β€” missing colon ─────────────────────────────────────
def is_even(number)
return number % 2 == 0


# ─── Bug 4: TYPE_ERROR β€” string + int ────────────────────────────────────────
def greet_user(name):
age = 25
message = "Hello " + name + " you are " + age + " years old"
return message


# ─── Bug 5: LOGIC error β€” wrong operator ─────────────────────────────────────
def is_positive(number):
if number < 0: # should be > 0
return True
return False


# ─── Bug 6: IMPORT error β€” wrong module name ─────────────────────────────────
from collections import OrderedDikt # typo: should be OrderedDict


# ─── Bug 7: LOGIC error β€” off-by-one in loop ─────────────────────────────────
def sum_list(numbers):
total = 0
for i in range(len(numbers) + 1): # should be range(len(numbers))
total += numbers[i]
return total


# ─── Bug 8: SYNTAX error β€” missing closing bracket ───────────────────────────
def get_square_roots(numbers):
return [math.sqrt(n) for n in numbers


# ─── Bug 9: TYPE_ERROR β€” wrong type comparison ───────────────────────────────
def count_above_threshold(numbers, threshold):
count = 0
for n in numbers:
if n > "threshold": # comparing int to string literal
count += 1
return count


# ─── Bug 10: LOGIC error β€” returns wrong value ───────────────────────────────
def fahrenheit_to_celsius(f):
return (f + 32) * 5 / 9 # should be (f - 32) * 5 / 9


# ─── Bug 11: INDENTATION error inside if block ───────────────────────────────
def classify_number(n):
if n > 0:
label = "positive"
elif n < 0:
label = "negative" # wrong indentation
else:
label = "zero"
return label


# ─── Bug 12: LINTING β€” variable defined but never used ───────────────────────
def multiply(a, b):
unused_variable = 42
return a * b
import math
from collections import OrderedDict


def calculate_area(length, width):
area = length * width
return area


def is_even(number):
return number % 2 == 0


def greet_user(name):
age = 25
message = "Hello " + name + " you are " + str(age) + " years old"
return message


def is_positive(number):
if number > 0:
return True
return False


def sum_list(numbers):
total = 0
for i in range(len(numbers)):
total += numbers[i]
return total


def get_square_roots(numbers):
return [math.sqrt(n) for n in numbers]


def count_above_threshold(numbers, threshold):
count = 0
for n in numbers:
if n > threshold:
count += 1
return count


def fahrenheit_to_celsius(f):
return (f - 32) * 5 / 9


def classify_number(n):
if n > 0:
label = "positive"
elif n < 0:
label = "negative"
else:
label = "zero"
return label


def multiply(a, b):
return a * b