diff --git a/src/utils.py b/src/utils.py index 54b964d..4693ad3 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,4 +1,2 @@ -import os # unused import — LINTING bug on line 1 - def add(a, b): - return a + b \ No newline at end of file + return a + b diff --git a/src/validator.py b/src/validator.py index 3df204f..341c0ff 100644 --- a/src/validator.py +++ b/src/validator.py @@ -1,2 +1,2 @@ -def validate(x) # missing colon — SYNTAX bug on line 1 - return x > 0 \ No newline at end of file +def validate(x): + return x > 0 diff --git a/tests/test_utils.py b/tests/test_utils.py index db0a721..1919a9b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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