neural-mesh-v2 / test_duplicate_function_behavior.py
hjkim00's picture
Restore all essential files - code, configs, and MBPP/HumanEval data
24c2665 verified
raw
history blame
3.08 kB
#!/usr/bin/env python3
"""
Test the behavior of duplicate function definitions
"""
from typing import List
# Case 1: ์ค‘๋ณต ํ•จ์ˆ˜ ์ •์˜ (์ค‘์ฒฉ๋œ ํ•จ์ˆ˜)
print("=== Case 1: Duplicate function definition ===")
code_duplicate = '''
def has_close_elements(numbers: List[float], threshold: float) -> bool:
""" Check if in given list of numbers, are any two numbers closer to each other than
given threshold.
>>> has_close_elements([1.0, 2.0, 3.0], 0.5)
False
>>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)
True
"""
def has_close_elements(numbers: List[float], threshold: float) -> bool:
for i in range(len(numbers) - 1):
for j in range(i + 1, len(numbers)):
if abs(numbers[i] - numbers[j]) < threshold:
return True
return False
'''
# ์‹คํ–‰ํ•˜๊ณ  ํ•จ์ˆ˜ ํ…Œ์ŠคํŠธ
exec(code_duplicate)
try:
# ์™ธ๋ถ€ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์‹ค์ œ๋กœ๋Š” ๋ณธ๋ฌธ์ด ์—†์–ด์„œ None์„ ๋ฐ˜ํ™˜
result = has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)
print(f"Result for [1.0, 2.8, 3.0, 4.0, 5.0, 2.0] with threshold 0.3: {result}")
print(f"Expected: True, Got: {result}")
print(f"Test {'PASSED' if result == True else 'FAILED'}")
except Exception as e:
print(f"Error: {e}")
# Case 2: ์ •์ƒ์ ์ธ ํ•จ์ˆ˜ ์ •์˜
print("\n=== Case 2: Normal function definition ===")
code_normal = '''
def has_close_elements_normal(numbers: List[float], threshold: float) -> bool:
""" Check if in given list of numbers, are any two numbers closer to each other than
given threshold.
"""
for i in range(len(numbers) - 1):
for j in range(i + 1, len(numbers)):
if abs(numbers[i] - numbers[j]) < threshold:
return True
return False
'''
exec(code_normal)
result = has_close_elements_normal([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)
print(f"Result for [1.0, 2.8, 3.0, 4.0, 5.0, 2.0] with threshold 0.3: {result}")
print(f"Expected: True, Got: {result}")
print(f"Test {'PASSED' if result == True else 'FAILED'}")
# Case 3: ๋‚ด๋ถ€ ํ•จ์ˆ˜์— return ๋ฌธ ์ถ”๊ฐ€
print("\n=== Case 3: Duplicate with explicit return ===")
code_duplicate_with_return = '''
def has_close_elements_fixed(numbers: List[float], threshold: float) -> bool:
""" Check if in given list of numbers, are any two numbers closer to each other than
given threshold.
"""
def has_close_elements_inner(numbers: List[float], threshold: float) -> bool:
for i in range(len(numbers) - 1):
for j in range(i + 1, len(numbers)):
if abs(numbers[i] - numbers[j]) < threshold:
return True
return False
# ๋‚ด๋ถ€ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด์„œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜
return has_close_elements_inner(numbers, threshold)
'''
exec(code_duplicate_with_return)
result = has_close_elements_fixed([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)
print(f"Result for [1.0, 2.8, 3.0, 4.0, 5.0, 2.0] with threshold 0.3: {result}")
print(f"Expected: True, Got: {result}")
print(f"Test {'PASSED' if result == True else 'FAILED'}")