file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f1245.py
|
def f(x: float) -> float:
return 1 if 0 <= x < 1 else 0
assert f(0.0) == 1
|
benchmark_functions_edited/f13037.py
|
def f(name, obj):
q = []
q.append(obj)
while q:
obj = q.pop(0)
if hasattr(obj, '__iter__'):
isdict = isinstance(obj, dict)
if isdict and name in obj:
return obj[name]
for k in obj:
q.append(obj[k] if isdict else k)
else:
return None
assert f(1, {1: 1}) == 1
|
benchmark_functions_edited/f9393.py
|
def f(val, min_val, max_val):
return min(max_val, max(min_val, val))
assert f(2, -1, 1) == 1
|
benchmark_functions_edited/f5993.py
|
def f(value):
if 1 <= int(value) <= 5:
return int(value)
raise ValueError("Expected rating between 1 and 5, but got %s" % value)
assert f("5") == 5
|
benchmark_functions_edited/f4731.py
|
def f(input_list):
out = 0
count = 0
while count < len(input_list):
out += input_list[count]
return out
assert f([]) == 0
|
benchmark_functions_edited/f4093.py
|
def f(x):
if x > 0:
return +1
elif x < 0:
return -1
elif x == 0:
return 0
assert f(3.14) == 1
|
benchmark_functions_edited/f5747.py
|
def f(*args):
for item in args:
if item is not None:
return item
return None
assert f(None, 2, 3) == 2
|
benchmark_functions_edited/f9796.py
|
def f(data, key, tpe, default=None):
value = data.get(key, default)
if not isinstance(value, tpe):
raise ValueError("Config error: {}: expected {}, found {}".format(
key, tpe, type(value)))
return value
assert f({"foo": 1}, "foo", int) == 1
|
benchmark_functions_edited/f5722.py
|
def f(indexable_container, index, default):
try:
return indexable_container[index]
except (IndexError, KeyError):
return default
assert f([1, 2, 3], 3, 0) == 0
|
benchmark_functions_edited/f9795.py
|
def f(input_):
sum = 0
for i in range(1, len(input_)):
if input_[i] > input_[i-1]:
sum += 1
return sum
assert f([1,1,1,1,1,1]) == 0
|
benchmark_functions_edited/f3699.py
|
def f(smaller, larger, M):
return larger + smaller * (M - 1) - smaller * (smaller - 1) // 2
assert f(1, 0, 2) == 1
|
benchmark_functions_edited/f8479.py
|
def f(options):
if not isinstance(options, dict):
return options
return {
option.replace('-', '_'): f(value)
for option, value in options.items()
}
assert f(1) == 1
|
benchmark_functions_edited/f9742.py
|
def f(vector, value):
if value < vector[0]:
return 0
for i in range(len(vector) + 1):
if value < vector[i + 1] and value > vector[i]:
return i + 1
return len(vector) - 1
assert f([0, 1, 2, 3, 4, 5], 2.5) == 3
|
benchmark_functions_edited/f2074.py
|
def f(number):
square = number**2
return square
assert f(-3) == 9
|
benchmark_functions_edited/f3587.py
|
def f(value):
index = int((6000-value)*8)
return index
assert f(6000) == 0
|
benchmark_functions_edited/f917.py
|
def f(arg):
return arg() if callable(arg) else arg
assert f(lambda: 1 + 1) == 2
|
benchmark_functions_edited/f3190.py
|
def f(x, position_num):
maxlen = int(position_num / 2)
return max(0, min(x + maxlen, position_num))
assert f(1, 3) == 2
|
benchmark_functions_edited/f6951.py
|
def f(v1, v2):
sum = 0.0
for c1, c2 in zip(v1, v2):
t = c1 - c2
sum += t * t
return sum
assert f(
[1, 2, 3],
[1, 2, 3]
) == 0
|
benchmark_functions_edited/f5027.py
|
def f(data,attr,default_value):
return data[attr] if attr in data.keys() else default_value
assert f(
{'foo': 1, 'bar': 2},
'foo',
100) == 1
|
benchmark_functions_edited/f4506.py
|
def f(value):
return 2*int(value//2)
assert f(2) == 2
|
benchmark_functions_edited/f11792.py
|
def f(start, dim_size):
if start is None:
return 0
if start < 0:
return 0 if start < -dim_size else start % dim_size
return start if start < dim_size else dim_size
assert f(-10, 1) == 0
|
benchmark_functions_edited/f6301.py
|
def f(value, size):
return value >> ((8 * size) - 1)
assert f(0x12, 1) == 0
|
benchmark_functions_edited/f3203.py
|
def f(float_time):
int_time = int(float_time * 10000000)
return int_time
assert f(0.0) == 0
|
benchmark_functions_edited/f12686.py
|
def f(arr, low, high):
i = (low-1)
pivot = arr[high]
for j in range(low, high):
if arr[j] <= pivot:
i = i+1
arr[i], arr[j] = arr[j], arr[i]
arr[i+1], arr[high] = arr[high], arr[i+1]
return (i+1)
assert f([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 0, 9) == 0
|
benchmark_functions_edited/f11273.py
|
def f(search_dictionary, search_key):
desired_key = [s for s in search_dictionary if search_key in s][0]
desired_value = search_dictionary[desired_key]
return desired_value
assert f(
{'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6}, 'E') == 5
|
benchmark_functions_edited/f5723.py
|
def f(t, b, c, d):
t /= d/2
if t < 1:
return c / 2 * t * t * t + b
t -= 2
return c/2 * (t * t * t + 2) + b
assert f(1, 0, 1, 1) == 1
|
benchmark_functions_edited/f10382.py
|
def f(start, ndim):
if start < -ndim or start > ndim:
raise ValueError(
f"For rollaxis, start {start} is out of bounds. Ranging from {-ndim} to {ndim} is allowed.")
if start < 0:
start = start + ndim
return start
assert f(0, 5) == 0
|
benchmark_functions_edited/f8044.py
|
def f(N):
distance=0
binary=bin(N)[2:]
found=binary.find("1")
for i in range(found+1,len(binary)):
if binary[i] == "1":
temp=i-found
found=i
distance = temp if temp > distance else distance
return distance
assert f(1) == 0
|
benchmark_functions_edited/f438.py
|
def f(n: int) -> int:
if n <= 1:
return 1
return n * f(n - 1)
assert f(0) == 1
|
benchmark_functions_edited/f6413.py
|
def f(node):
if node is None:
return 0
return node.size
assert f(None) == 0
|
benchmark_functions_edited/f5199.py
|
def f(a, b, **kwargs):
sum = a + b
for key, value in sorted(kwargs.items()):
sum += value
return sum
assert f(3, 4) == 7
|
benchmark_functions_edited/f13205.py
|
def f(dataset, slice_arg):
if isinstance(dataset, dict):
transformed = {key: data[slice_arg] for key, data in dataset.items()}
else:
transformed = dataset[slice_arg]
return transformed
assert f(range(10), 0) == 0
|
benchmark_functions_edited/f10486.py
|
def f(a, b):
try:
return a - b
except TypeError:
return 2
assert f([1], [2,3]) == 2
|
benchmark_functions_edited/f13648.py
|
def f(lst: list) -> int:
left, right = 0, len(lst) - 1
while left <= right:
mid = (left + right) // 2
if lst[mid] == mid:
return mid
if lst[mid] > mid:
right = mid - 1
else:
left = mid + 1
return -1
assert f(list(range(5))) == 2
|
benchmark_functions_edited/f3286.py
|
def f(freqs):
d = (freqs - 1000) / 15
return d
assert f(1000) == 0
|
benchmark_functions_edited/f2163.py
|
def f(num, offset):
mask = 1 << offset
return num & mask
assert f(14, 0) == 0
|
benchmark_functions_edited/f784.py
|
def f(rbg, percent):
return rbg * (100-percent)/100
assert f(100, 100) == 0
|
benchmark_functions_edited/f6733.py
|
def f(true_entities, pred_entities):
nb_correct = len(true_entities & pred_entities)
nb_true = len(true_entities)
score = nb_correct / nb_true if nb_true > 0 else 0
return score
assert f(set(), set()) == 0
|
benchmark_functions_edited/f13769.py
|
def f(packCig) :
nb_cig = (len(packCig[0]), len(packCig[1]), len(packCig[2]))
if nb_cig[0] == nb_cig[1] and nb_cig[0] == nb_cig[2] :
return nb_cig[0]
else :
raise ValueError(" Erreur de len() au niveau des listes dans les listes")
assert f([[], [], []]) == 0
|
benchmark_functions_edited/f6795.py
|
def f(jac_list):
if len(jac_list) == 0:
return 0
return sum(jac_list)/float(len(jac_list))
assert f(range(0)) == 0
|
benchmark_functions_edited/f10120.py
|
def f(o):
if isinstance(o, float):
return round(o, 6)
if isinstance(o, dict):
return {k: f(v) for k, v in o.items()}
if isinstance(o, (list, tuple)):
return [f(x) for x in o]
return o
assert f(1) == 1
|
benchmark_functions_edited/f1925.py
|
def f(z):
return 1*(z > 0)
assert f(-0.5) == 0
|
benchmark_functions_edited/f7933.py
|
def f(val):
for func in [int, float, lambda x: x.strip(), lambda x: x]:
try:
return func(val)
except ValueError:
pass
assert f(' 0') == 0
|
benchmark_functions_edited/f8943.py
|
def f(left, right) -> int:
max_overlap = min(len(left), len(right))
for i in range(max_overlap, 0, -1):
if left.endswith(right[:i]):
return i
return 0
assert f(
"abcdefg",
"abcdefg"
) == 7
|
benchmark_functions_edited/f4259.py
|
def f(t, y):
# dFPdt = (T/(m*v)) * np.sin(alpha+delta) + Lift/(m*v) - g*np.cos(FP)
return 0
assert f(10, 20) == 0
|
benchmark_functions_edited/f11414.py
|
def median_s (sorted_seq) :
l = len (sorted_seq)
if l % 2 :
result = sorted_seq [l // 2]
else :
l -= 1
result = (sorted_seq [l // 2] + sorted_seq [l // 2 + 1]) / 2.0
return result
assert f( [1, 2, 2, 3, 14] ) == 2
|
benchmark_functions_edited/f12466.py
|
def f(offset, document):
value = document
for key in offset:
value = value[key]
return value
assert f(
['a', 'b'],
{'a': {'b': 4}}) == 4
|
benchmark_functions_edited/f7293.py
|
def f(vec1, vec2):
# f([1, 2, 3], [1, 2, 3]) -> 14
return sum(map(lambda x, y: x * y, vec1, vec2))
assert f([], []) == 0
|
benchmark_functions_edited/f9648.py
|
def f(t, tempo, div):
return tempo * t / (1000.0 * div)
assert f(0, 500000, 120) == 0
|
benchmark_functions_edited/f12710.py
|
def f(level, maxval):
return int(level * maxval / 10)
assert f(6, 10) == 6
|
benchmark_functions_edited/f8891.py
|
def f(cand_d, ref_ds):
count = 0
for m in cand_d.keys():
m_w = cand_d[m]
m_max = 0
for ref in ref_ds:
if m in ref:
m_max = max(m_max, ref[m])
m_w = min(m_w, m_max)
count += m_w
return count
assert f(
{
"this": 2,
"is": 1,
},
[
{
"this": 1,
},
{
"this": 1,
},
]
) == 1
|
benchmark_functions_edited/f12040.py
|
def f(input, metadata):
if float(input).is_integer():
return int(input)
else:
raise ValueError(f"Invalid integer: '{input}'")
assert f("5", None) == 5
|
benchmark_functions_edited/f8413.py
|
def f(n, bit_length):
return (1 << bit_length) - 1 - n
assert f(2, 3) == 5
|
benchmark_functions_edited/f7129.py
|
def f(x: int, y: int):
assert isinstance(x, int) and isinstance(y, int)
assert y != 0
assert x % y == 0, f'{x} is not divisible by {y}.'
return x // y
assert f(6, 2) == 3
|
benchmark_functions_edited/f11475.py
|
def f(vec1, vec2):
diff0 = vec1[0] - vec2[0];
diff1 = vec1[1] - vec2[1];
diff2 = vec1[2] - vec2[2];
result = diff0 * diff0 + diff1 * diff1 + diff2 * diff2;
return result
assert f(
(-1, -1, -1),
(0, 0, 0)
) == 3
|
benchmark_functions_edited/f421.py
|
def f(n):
return (n+1)
assert f(6) == 7
|
benchmark_functions_edited/f4815.py
|
def f(a, b):
while True:
if b == 0:
return a
a, b = b, a % b
assert f(12, 10) == 2
|
benchmark_functions_edited/f13498.py
|
def f(value_to_be_ranked, value_providing_rank):
num_lesser = [v for v in value_providing_rank if v < value_to_be_ranked]
return len(num_lesser)
assert f(4, [1, 2, 3, 4]) == 3
|
benchmark_functions_edited/f9321.py
|
def f(integ, frac, n=32):
return integ + float(frac)/2**n
assert f(0, 0) == 0
|
benchmark_functions_edited/f11767.py
|
def f(obj: dict, name: str) -> int:
value = obj[name]
if not isinstance(value, int):
raise TypeError(
f'{name} must be integer: {type(value)}')
elif value < 0:
raise ValueError(
f'{name} must be positive integer: {value}')
return value
assert f(
{'value': 5}, 'value') == 5
|
benchmark_functions_edited/f4751.py
|
def f(I: float) -> float:
return ((1+I)**(30/360))-1
assert f(0) == 0
|
benchmark_functions_edited/f7272.py
|
def f(x, y, serial):
rack_id = x + 10
power = (((rack_id*y) + serial) * rack_id)
if power > 99:
return (power // 100) % 10 - 5
else:
return -5
assert f(217, 196, 39) == 0
|
benchmark_functions_edited/f1153.py
|
def f(mu, E):
return E/(2*(1+mu))
assert f(0.5, 0) == 0
|
benchmark_functions_edited/f8220.py
|
def f(observed, expected):
total = 0
for i in range(len(observed)):
total += (((observed[i] - expected[i])**2)/expected[i])
return total
assert f([2,4,6,8,10],[2,4,6,8,10]) == 0
|
benchmark_functions_edited/f13728.py
|
def f(set_of_contributors, anonymous_coward_comments_counter):
user_count = len(set_of_contributors)
return user_count
assert f(set([1, 2, 3, 4, 5, 6, 7]), 8) == 7
|
benchmark_functions_edited/f3639.py
|
def f(state):
n = 0
for s in state:
if s != 0:
n += 1
return n
assert f(list('ab')) == 2
|
benchmark_functions_edited/f447.py
|
def f(A, B):
return A / (A + B)
assert f(0, 10) == 0
|
benchmark_functions_edited/f14179.py
|
def f(p, p_other_lag, p_own_lag, rounder_number):
state = (p_other_lag, p_own_lag)
if p == 2 and state == (1,1):
return 1
elif p == 1 and state == (4,2):
return 1
elif p == 2 and state == (4,4):
return 1
elif rounder_number == 1 and p == 2:
return 1
else:
return 0
assert f(2, 4, 4, 2) == 1
|
benchmark_functions_edited/f8642.py
|
def f(S, j):
return (S & (1 << j)) >> j
assert f(0b000000, 0) == 0
|
benchmark_functions_edited/f12838.py
|
def f(n):
if n in [0, 1]: # The special case of n being 0 or 1
return 1
a = 1
b = 0
fib_sequence=[]
for i in range(n - 1):
temp = b # A temporary variable to remember the value of b
b = a + b # New value of b
fib_sequence.append(b)
a = temp # New value of a (old value of b)
return fib_sequence
assert f(1) == 1
|
benchmark_functions_edited/f13759.py
|
def f(matrix):
minorValue = [0, 999999]
for i in range(len(matrix)):
if matrix[i][-1] <= minorValue[1]:
minorValue[0] = i
minorValue[1] = matrix[i][-1]
return minorValue[0]
assert f(
[[2, 0, 0], [4, 0, 3], [0, 0, 5]]) == 0
|
benchmark_functions_edited/f2017.py
|
def dec2bin (x):
return int(bin(x)[2:])
assert f(0) == 0
|
benchmark_functions_edited/f4945.py
|
def f(ls):
unique = []
for val in ls:
if val not in unique:
unique.append(val)
return len(unique)
assert f([1.0, 2.0, 3.0, 4.0, 4.0, 4.0, 4.0, 4.0]) == 4
|
benchmark_functions_edited/f6560.py
|
def f(vlist, current_val):
return vlist[(vlist.index(current_val) + 1) % len(vlist)]
assert f(range(1, 4), 1) == 2
|
benchmark_functions_edited/f10855.py
|
def f(present_t, start_t, lap):
if present_t - start_t >= lap:
start_t = present_t
return start_t
assert f(3, 1, 15) == 1
|
benchmark_functions_edited/f7555.py
|
def f(f, *args):
return sum(f(*a) for a in zip(*args))
assert f(lambda l: l[0], [[1, 2, 3], [4, 5]]) == 5
|
benchmark_functions_edited/f4011.py
|
def f(n):
return max(1, int(round(int(n)/3.3219280948873626)-1))
assert f(0.5) == 1
|
benchmark_functions_edited/f10348.py
|
def f(N, M):
from itertools import permutations
nums = range(M)
count = 0
for a in permutations(nums, N):
for b in permutations(nums, N):
if all(a[i] != b[i] for i in range(N)):
count += 1
return count
assert f(2, 2) == 2
|
benchmark_functions_edited/f11808.py
|
def f(target):
operation = 0
while target > 0:
if target % 2 == 0:
target = target // 2
else:
target = target - 1
operation += 1
return operation
assert f(100) == 9
|
benchmark_functions_edited/f3849.py
|
def f(num: int) -> int:
return num ^ max(1, 2 ** (num).bit_length() - 1)
assert f(12) == 3
|
benchmark_functions_edited/f2921.py
|
def f(num):
if num in (0, 1): # f(0) == 0, f(1) == 1
return num
return f(num - 2) + f(num - 1)
assert f(1) == 1
|
benchmark_functions_edited/f2597.py
|
def f(a):
if a is None: return 0
(x, y, w, h) = a
return float(w) / h
assert f(None) == 0
|
benchmark_functions_edited/f9270.py
|
def f(v1, v2=None):
if not v2:
v2 = v1
result = 0
for i in range(len(v1)):
result += v1[i] * v2[i]
return result
assert f([]) == 0
|
benchmark_functions_edited/f9144.py
|
def f(array: list):
array.sort()
missing = 0
for index, number in enumerate(array):
if index != number:
missing = index
print(f'Missing from the continuous sequence: {index}')
break
return missing
assert f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0
|
benchmark_functions_edited/f9453.py
|
def f(text):
c = text.count("!")
return c
assert f(
"Hey!"
) == 1
|
benchmark_functions_edited/f11126.py
|
def f(x, y, img):
return img[y][x]
assert f(0, 0, [[0, 1], [2, 3]]) == 0
|
benchmark_functions_edited/f9988.py
|
def f(numbers):
total = 0
for number in numbers:
result = numbers.count(number)
if result >= 2:
print(number)
else:
total += number
return total
assert f([1, 1, 1, 1]) == 0
|
benchmark_functions_edited/f2617.py
|
def f(Qval, reward, alpha):
return Qval + alpha * (reward - Qval)
assert f(0, 0, 0.0) == 0
|
benchmark_functions_edited/f3163.py
|
def mean (nums):
return float(sum(nums))/len(nums)
assert f([3, 4, 5]) == 4
|
benchmark_functions_edited/f9484.py
|
def f(node_list):
node_list = [n for n in node_list if n is not None]
if node_list == []:
return None
from operator import add
from functools import reduce
return reduce(add, node_list)
assert f([5]) == 5
|
benchmark_functions_edited/f9554.py
|
def f(gen):
sum_ = 0
for index, val in enumerate(gen, 1):
if index % 2:
val *= 2
sum_ += val // 10 + val % 10
else:
sum_ += val
return (10 - sum_ % 10) % 10
assert f(range(1000, 11000)) == 0
|
benchmark_functions_edited/f4421.py
|
def f(seq_list):
lmax=0
for seq in seq_list:
lmax=max( lmax, len(seq) )
return lmax
assert f( ['ABC', 'DE'] ) == 3
|
benchmark_functions_edited/f7135.py
|
def toBCD (n):
bcd = 0
bits = 0
while True:
n, r = divmod(n, 10)
bcd |= (r << bits)
if n is 0:
break
bits += 4
return bcd
assert f(7) == 7
|
benchmark_functions_edited/f229.py
|
def f(a,b):
c=a+b
return c
assert f(-1,2) == 1
|
benchmark_functions_edited/f11910.py
|
def f(bb_1, bb_2):
if ( (bb_1[0] > bb_2[1]) and (bb_1[1] < bb_2[0]) and
(bb_1[2] > bb_2[3]) and (bb_1[3] < bb_2[2]) ):
return 1
else:
return 0
assert f( (1,2,3,4), (3,3,3,3) ) == 0
|
benchmark_functions_edited/f13588.py
|
def f(room:str):
# the string is checked
if room == "Private room":
return 0
if room == "Entire home/apt":
return 1
if room == "Hotel room":
return 2
if room == "Shared room":
return 3
assert f( "Shared room" ) == 3
|
benchmark_functions_edited/f2231.py
|
def f(array):
if len(array) < 1:
return 0
return max(array) - min(array)
assert f([0,1,2,3,4,5,6,7,8,9]) == 9
|
benchmark_functions_edited/f3013.py
|
def f(values):
return sum(values) / len(values)
assert f([0, 2, 4]) == 2
|
benchmark_functions_edited/f6928.py
|
def f(text):
text = text.replace(" ","")
if len(text) == 0:
return 0
return sum([1 for i in text if i.isupper()])/len(text)
assert f(u" ") == 0
|
benchmark_functions_edited/f1921.py
|
def f(a, b):
return float(2*a*b) / (a + b)
# return harmonic_mean([a, b])
assert f(1, 0) == 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.