file_name stringlengths 32 36 | content stringlengths 44 898 |
|---|---|
benchmark_functions_edited/f10604.py | def f(istring):
try:
return float(istring.strip())
except Exception:
return 0
assert f("1e-3kg") == 0 |
benchmark_functions_edited/f13707.py | def f(arr: list):
ret = 0
for i in arr:
if i.position > ret:
ret = i.position
return ret
assert f([]) == 0 |
benchmark_functions_edited/f2160.py | def f(a, b):
return (not a) != (not b)
assert f(False, 1) == 1 |
benchmark_functions_edited/f7521.py | def f(location_type):
rtn_value = 0
if location_type.lower() in ['project']:
rtn_value = 1
return rtn_value
assert f('project') == 1 |
benchmark_functions_edited/f3930.py | def f(s):
try:
return int(s)
except ValueError:
return s
assert f(5) == 5 |
benchmark_functions_edited/f1678.py | def f(img1,img2,alpha):
return (1 - alpha)*img1 + alpha * img2
assert f(0, 0, 1) == 0 |
benchmark_functions_edited/f4974.py | def f(number):
if number == 0:
return 0
else:
return number.rstrip('0').rstrip('.') if '.' in number else number
assert f(0) == 0 |
benchmark_functions_edited/f8690.py | def f(topicCoOccurrenceList, coOccurrenceDict):
sumNZ = 0
for topicCoOccurrence in topicCoOccurrenceList:
if coOccurrenceDict[topicCoOccurrence] == 0.0:
sumNZ += 1
return sumNZ
assert f(
[1, 2, 3],
{1: 0.0, 2: 2.0, 3: 2.0}
) == 1 |
benchmark_functions_edited/f9342.py | def f(rho, rnorm, snorm, iteration=None, mu=10, tau_inc=2, tau_dec=2):
if rnorm > mu * snorm:
return tau_inc * rho
elif snorm > mu * rnorm:
return rho / tau_dec
return rho
assert f(1, 1, 1, 10) == 1 |
benchmark_functions_edited/f10795.py | def f(c, tweets):
tp = 0
fn = 0
for tweet in tweets:
if c in tweet['tags']:
if c in tweet['predictions']:
tp+=1
else:
fn+=1
if tp+fn == 0:
return float('nan')
return tp/(tp+fn)
assert f(1, [
{'text': 'the quick brown fox jumps over the lazy dog',
'tags': [1, 2, 3],
'predictions': [1, 2]},
{'text': 'a lazy dog jumps over the brown fox',
'tags': [2, 3],
'predictions': [1, 2]},
{'text': 'a quick brown fox jumps over a lazy dog',
'tags': [1, 2, 3],
'predictions': [1, 2]}]) == 1 |
benchmark_functions_edited/f9922.py | def f(weighted_list):
if len(weighted_list) > 0:
return sum([val * wgt for val, wgt in weighted_list]) /\
sum([wgt for _, wgt in weighted_list])
else:
return 0
assert f(list()) == 0 |
benchmark_functions_edited/f13057.py | def f(ops, key_func):
maximum = 0
for i in range(len(ops)):
if ops[i][key_func] > maximum:
maximum = ops[i][key_func]
return maximum
assert f(
[
{"min": 1, "max": 2},
{"min": 3, "max": 4},
{"min": 5, "max": 6}
],
"min"
) == 5 |
benchmark_functions_edited/f11085.py | def f(firstIndex: int, secondIndex: int, targetLetter: str, password: str) -> int:
bool1: bool = password[firstIndex - 1] == targetLetter
bool2: bool = password[secondIndex - 1] == targetLetter
return 1 if bool1 ^ bool2 else 0
assert f(1, 3, "b", "a<PASSWORD>") == 0 |
benchmark_functions_edited/f8714.py | def f(d1, d2):
m1 = d1.get('_last_accessed', 0)
m2 = d2.get('_last_accessed', 0)
if m1 == m2:
return 0
if m1 > m2:
return -1 # d1 is "less than" d2
return 1
assert f(
{'key': 'value1'},
{'key': 'value1'}
) == 0 |
benchmark_functions_edited/f1.py | def f(x):
return x**2 + x + 3
assert f(0) == 3 |
benchmark_functions_edited/f1844.py | def f(iterable, default=None):
return next(iter(iterable), default)
assert f(range(10), 8) == 0 |
benchmark_functions_edited/f2233.py | def f(low: float, high: float):
return low + (high - low) / 2
assert f(-5, 5) == 0 |
benchmark_functions_edited/f12913.py | def f(arr):
m = min(arr)
if m > 0:
return (m * -1) + 1
else:
m = (m * -1) + 1
running_sum = m
for val in arr:
if running_sum + val >= 1:
running_sum += val
else:
m += 1 - (running_sum + val)
running_sum = 1
return m
assert f( [1, 0, 10] ) == 1 |
benchmark_functions_edited/f9789.py | def f(field: str) -> int:
if field != "":
hour = int(field[0:2])
minute = int(field[2:4])
second = int(field[4:6])
return 1000000 * ((3600 * hour) + (60 * minute) + second)
else:
return 0
assert f(
""
) == 0 |
benchmark_functions_edited/f7822.py | def f(iterable):
product = 1
for x in iterable:
product *= x
return product
assert f([-1, 0, 1]) == 0 |
benchmark_functions_edited/f9666.py | def f(linkArray):
result = 0
for row in linkArray:
result = result + len(row)
return result
assert f([[]]) == 0 |
benchmark_functions_edited/f6862.py | def f(l):
return next(iter(l), None)
assert f(list(range(3))) == 0 |
benchmark_functions_edited/f9443.py | def f(row):
if len(row) > 0 and row[0]["bbox"] is not None:
return row[0]["bbox"][0]
else:
return 0.0
assert f(
[
{"bbox": [1, 2, 3, 4]},
{"bbox": [2, 2, 3, 4]}
]
) == 1 |
benchmark_functions_edited/f3482.py | def f(total_count: int, this_count: int):
return -(-total_count // this_count)
assert f(9, 3) == 3 |
benchmark_functions_edited/f3623.py | def f(n):
res = 1
for i in range(n):
res *= i+1
return res
assert f(0) == 1 |
benchmark_functions_edited/f12397.py | def f(e, candidate_idx, token_idx):
c = e["long_answer_candidates"][candidate_idx]
char_offset = 0
for i in range(c["start_token"], token_idx):
t = e["document_tokens"][i]
if not t["html_token"]:
token = t["token"].replace(" ", "")
char_offset += len(token) + 1
return char_offset
assert f(
{
"document_tokens": [{"token": "hi", "html_token": False}, {"token": "there", "html_token": False}],
"long_answer_candidates": [{"start_token": 0, "end_token": 0}]
},
0,
0
) == 0 |
benchmark_functions_edited/f4130.py | def f(bin: int) -> int:
num = bin & 0xFFFF
return num - 0x010000 if 0x8000 & num else num
assert f(0b0000000000000001) == 1 |
benchmark_functions_edited/f11294.py | def f(lst):
result = 0 # Accumulator
for x in lst:
result = result+x
return result
assert f([0,0,0,0,0]) == 0 |
benchmark_functions_edited/f9542.py | def f(hour_in, check_in, tolerance):
if check_in > hour_in:
if (check_in - hour_in) < tolerance:
result = ' '
else:
result = check_in - hour_in
else:
result = ' '
return result
assert f(2, 3, 1) == 1 |
benchmark_functions_edited/f5082.py | def f(Married):
if Married == 'Yes':
return 1
else:
return 0
assert f(5) == 0 |
benchmark_functions_edited/f4206.py | def f(diagonal_1, diagonal_2):
# You have to code here
# REMEMBER: Tests first!!!
return (1/2) * diagonal_1 * diagonal_2
assert f(3, 4) == 6 |
benchmark_functions_edited/f9531.py | def f(n: int ):
facto= 1
for i in range(1,n+1):
facto = facto * i
return facto
assert f(1) == 1 |
benchmark_functions_edited/f3092.py | def f(a, b, c=2):
print('exec add3')
ret = a + b + c
print('add3: %s + %s + %s = %s' % (a, b, c, ret))
return ret
assert f(2, 2, 2) == 6 |
benchmark_functions_edited/f915.py | def f(bitboard):
return bitboard.bit_length() - 1
assert f(0b1) == 0 |
benchmark_functions_edited/f6720.py | def f(a: str, b: str) -> int:
min_len = min(len(a), len(b))
for i in range(min(len(a), len(b))):
if a[i] != b[i]:
return i
return min_len
assert f(
"x",
"y",
) == 0 |
benchmark_functions_edited/f10188.py | def f(base: int, exponent: int, modulus: int) -> int:
result = 1
temp = base % modulus
while exponent > 0:
if exponent & 1:
result = (result * temp) % modulus
temp = (temp * temp) % modulus
exponent >>= 1
return result
assert f(10, 0, 100) == 1 |
benchmark_functions_edited/f5939.py | def f(n):
retVal = 0
aStr = str(n)
for digit in aStr:
retVal += int(digit) ** 2
return retVal
assert f(12) == 5 |
benchmark_functions_edited/f5398.py | def f(hand):
return sum(hand.values())
assert f({}) == 0 |
benchmark_functions_edited/f10090.py | def f(x, y):
return -x ** 2 - (y - 1) ** 2 + 1
assert f(1, 1) == 0 |
benchmark_functions_edited/f14346.py | def f(array, left, right):
while array[left] > array[right]:
mid = left + (right - left) // 2
if array[mid] < array[right]:
right = mid
else:
left = mid + 1
return array[left]
assert f([1,2,3,4,5,6], 0, 5) == 1 |
benchmark_functions_edited/f7897.py | def f(t, params):
import random
if params == None:
b_min = 0.1
b_max = 1.0
else:
b_min = params['min']
b_max = params['max']
velocity = random.uniform(b_min, b_max)
return velocity
assert f(0, {'min': 0,'max': 0}) == 0 |
benchmark_functions_edited/f12062.py | def f(list_, value):
first = 0
last = len(list_) - 1
while first <= last:
middle = first + (last - first) // 2
if value == list_[middle]:
return middle
elif value < list_[middle]:
last = middle - 1
else:
first = middle + 1
return None
assert f([1, 3, 5, 6, 9, 13], 5) == 2 |
benchmark_functions_edited/f2517.py | def f(*vars):
v = 1
for i in vars:
v *= i
return v
assert f(1, 2) == 2 |
benchmark_functions_edited/f12742.py | def f(index, date):
x = [i for i, elem in enumerate(index) if elem == date]
if x == []:
raise ValueError('Date does not exists: ' + date.__repr__())
return x[0]
assert f(
['2018-01-01', '2018-02-01', '2018-03-01', '2018-04-01'],
'2018-02-01'
) == 1 |
benchmark_functions_edited/f10408.py | def f(idx, value, n):
if idx == value:
return 0
# zero is not a tile
elif value == 0:
return 0
else:
term1 = divmod(value, n)
term2 = divmod(idx, n)
return sum(abs(x - y) for x, y in zip(term1, term2))
assert f(0, 3, 3) == 1 |
benchmark_functions_edited/f1640.py | def f(value):
return sum(1 for char in value.lower() if char in "aeiou")
assert f("y") == 0 |
benchmark_functions_edited/f13873.py | def f(a, b):
if a == 0: return 0
result = 1
while a > 1:
if a & 1:
if ((a-1)*(b-1) >> 2) & 1:
result = -result
a, b = b % a, a
else:
if (((b * b) - 1) >> 3) & 1:
result = -result
a >>= 1
if a == 0: return 0
return result
assert f(13, 13) == 0 |
benchmark_functions_edited/f9226.py | def f(a, b):
if len(b) != len(a):
return None
product = 0
for a_i, b_i in zip(a, b):
try:
product += a_i * b_i
except TypeError:
return None
return product
assert f((1, 1), (2, 3)) == 5 |
benchmark_functions_edited/f5683.py | def f(field):
value = 0
if field == 'identifier':
value = 0
if field == 'link':
value = 1
return value
assert f('identifier') == 0 |
benchmark_functions_edited/f1804.py | def f(value):
age = int(value)
return int(age / 10)
assert f(75) == 7 |
benchmark_functions_edited/f11668.py | def f(first, second=0, third=2):
first = int(first)
return first + first
assert f(1, 0) == 2 |
benchmark_functions_edited/f12968.py | def f(content, letter):
if (not isinstance(letter, str)) or len(letter) != 1:
raise ValueError('`letter` must be a single character string.')
return len([char for char in content if char == letter])
assert f(
'The quick brown fox jumps over the lazy dog.', 'o'
) == 4 |
benchmark_functions_edited/f12867.py | def f(a, b):
if 0 in (a, b):
return 1
if a < b:
return f(a, b - a)
elif b < a:
return f(a - b, a)
return a
assert f(2, 4) == 2 |
benchmark_functions_edited/f1561.py | def f(iterable):
return next(iter(iterable))
assert f(range(100)) == 0 |
benchmark_functions_edited/f6518.py | def f(value, start):
div = 1
for d in range(start, 0, -1):
if (value % d) == 0:
div = d
break
return div
assert f(2, 2) == 2 |
benchmark_functions_edited/f1498.py | def f(a, b):
result = a * b
return result
assert f(2, 3) == 6 |
benchmark_functions_edited/f11911.py | def f(n, exp):
y = 1
while exp > 1:
if exp % 2 == 1:
y *= n
n *= n
exp = (exp-1) // 2
else:
n **= 2
exp //= 2
return n * y
assert f(1, 1) == 1 |
benchmark_functions_edited/f40.py | def f(elt):
return elt['z']
assert f(
{'z': 9, 'Z': 9, 'atomic_number': 9, 'Atomic_Number': 9}
) == 9 |
benchmark_functions_edited/f4445.py | def f(x):
if x < 0:
return 0
elif x < 1:
return x
else:
return 1
assert f(100) == 1 |
benchmark_functions_edited/f8866.py | def f(gen, mi, ma):
ans = gen()
if ans >= ma:
return ma
if ans <= mi:
return mi
return ans
assert f(lambda: -5, 0, 10) == 0 |
benchmark_functions_edited/f6942.py | def f(register_offset, port_number, register_type):
return (register_offset * register_type) + port_number
assert f(1, 2, 0x00) == 2 |
benchmark_functions_edited/f12214.py | def f(b):
value, tile = 0, -1
# Retrieve the largest value.
for row in b:
for cell in row:
if cell > tile:
tile = cell
# Check if the tile is in the desired location.
if b[0][0] == tile:
value += (1024 * tile)
return value
assert f(
[
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
],
) == 0 |
benchmark_functions_edited/f10805.py | def f(typical_loss): #87 (line num in coconut source)
#88 (line num in coconut source)
a, b = float(abs(typical_loss)).as_integer_ratio() #89 (line num in coconut source)
little_a = int("1" * len(str(a))) #90 (line num in coconut source)
return little_a / b
assert f(-1.0) == 1 |
benchmark_functions_edited/f10219.py | def f(val, default=0xDEADBEEF):
try:
return int(val)
except (TypeError, ValueError):
if default != 0xDEADBEEF:
return default
return val
assert f(False) == 0 |
benchmark_functions_edited/f9424.py | def f(*args, raise_if_all_none=None):
for a in args:
if a is not None:
return a
if raise_if_all_none is not None:
raise raise_if_all_none
return None
assert f(1, 2, 3, 4, 5) == 1 |
benchmark_functions_edited/f7079.py | def f(a,b):
return (len(set.intersection(a,b))-1)/len(a)
assert f({1},{1}) == 0 |
benchmark_functions_edited/f236.py | def f(a):
return (a == 'H' or a == 'D')
assert f(11) == 0 |
benchmark_functions_edited/f9862.py | def f(n, m, indices):
# initialize variables
row, col = [False] * n, [False] * m
# iterate through indices
for r, c in indices:
row[r] ^= True
col[c] ^= True
return sum(rows ^ colm for rows in row for colm in col)
assert f(2, 3, [(1, 1)]) == 3 |
benchmark_functions_edited/f839.py | def f(dictionary, key):
return dictionary.get(key)
assert f(
{'a': 1, 'b': 2, 'c': 3},
'c',
) == 3 |
benchmark_functions_edited/f3384.py | def f(predicate, iterable):
return sum(1 for item in iterable if predicate(item))
assert f(lambda x: x > 2, []) == 0 |
benchmark_functions_edited/f6226.py | def f(inputstr):
vowels = ['a', 'e', 'i', 'o', 'u']
count = 0
for letter in inputstr:
if letter in vowels:
count += 1
return(count)
assert f('mango') == 2 |
benchmark_functions_edited/f3698.py | def f(canv):
return (canv and len(canv[0])) or 0
assert f([['a', 'b']]) == 2 |
benchmark_functions_edited/f253.py | def f(l: list) -> int:
return l.index(max(l))
assert f([-1, 2, 0]) == 1 |
benchmark_functions_edited/f1983.py | def f(*values):
return next((v for v in values if v is not None), None)
assert f(None, None, 3) == 3 |
benchmark_functions_edited/f1460.py | def f(a, b):
while b > 0:
a, b = b, a % b
return a
assert f(4, 12) == 4 |
benchmark_functions_edited/f4971.py | def f(func, *args, **kwargs):
if func and callable(func):
return func(*args, **kwargs)
return None
assert f(lambda x, y: x, 1, 2) == 1 |
benchmark_functions_edited/f266.py | def f(m, n):
if n == 1:
return m
return m + f(m, n-1)
assert f(4, 2) == 8 |
benchmark_functions_edited/f984.py | def f(l):
if len(l) == 0:
return 0
return sum(l)/len(l)
assert f([]) == 0 |
benchmark_functions_edited/f3771.py | def f(n):
if n % 2 == 0:
n = n // 2
else:
n = 3 * n + 1
return n
assert f(2) == 1 |
benchmark_functions_edited/f12427.py | def f(b, e, n):
assert b >= 1 and e >= 1 and n >= 1, "b, e and n must all be > 0"
result = b if (e & 1) else 1
exp_bit_len = e.bit_length()
for x in range(1, exp_bit_len):
b = (b ** 2) % n
if (e >> x) & 1:
result = (result * b) % n
return result
assert f(2, 6, 5) == 4 |
benchmark_functions_edited/f2946.py | def f(str, set):
for c in set:
if c in str: return 1
return 0
assert f( "foobar", "foo" ) == 1 |
benchmark_functions_edited/f4919.py | def f(n: int) -> int:
s = str(n)
return int(s[0])
assert f(123456) == 1 |
benchmark_functions_edited/f299.py | def f(num):
return int(num * 100)
assert f(0.0) == 0 |
benchmark_functions_edited/f1321.py | def f(a: int, b: int) -> int:
return (a + b - 1) // b
assert f(4, 3) == 2 |
benchmark_functions_edited/f13595.py | def f(str1, str2):
if len(str1) != len(str2):
return None
hamming_dist = 0
for i_char, _ in enumerate(str1):
if str1[i_char] != str2[i_char]:
hamming_dist += 1
return hamming_dist
assert f("ab", "ac") == 1 |
benchmark_functions_edited/f6134.py | def f(n: int) -> int:
from math import ceil, sqrt
return (2 * n) + ceil(2 * sqrt(n))
assert f(1) == 4 |
benchmark_functions_edited/f6616.py | def f(x:float, y:float) -> float:
return abs(x - y)
assert f(15, 7) == 8 |
benchmark_functions_edited/f10983.py | def f(attr_value):
if attr_value is None:
return "|" # '|' is a non-legal character and this is used to prevent
# collisions between similar attributes
else:
return attr_value
assert f(1) == 1 |
benchmark_functions_edited/f9469.py | def any (pred, seq):
for i in seq:
if pred(i): return 1
return 0
assert f(lambda x: x == 1, [2, 3, 4, 5]) == 0 |
benchmark_functions_edited/f4069.py | def f(z0, z1, p):
return (1-p)*z0+p*z1
assert f(1, 2, 0) == 1 |
benchmark_functions_edited/f2381.py | def f(numbers):
result = 1
for number in numbers:
result *= number
return result
assert f([1, 2, 3]) == 6 |
benchmark_functions_edited/f10030.py | def f(grid, current):
if grid[current[0]][current[1]] == '.':
return 0
elif grid[current[0]][current[1]] == '#':
return 1
else:
print("And I oop...color_coder")
assert f(
[['.', '#', '.'],
['.', '.', '#'],
['#', '#', '.']],
(0, 0)
) == 0 |
benchmark_functions_edited/f7827.py | def f(cache, element):
try:
return cache[cache.index(element)]
except ValueError:
return element
assert f([1], 1) == 1 |
benchmark_functions_edited/f5362.py | def f(label1, label2):
return (len(label1.union(label2)) -
len(label1.intersection(label2)))/len(label1.union(label2))
assert f(set("ab"), set("ab")) == 0 |
benchmark_functions_edited/f4079.py | def f(p1, p2):
x = p1[0] - p2[0]
y = p1[1] - p2[1]
return x * x + y * y
assert f(
(1, 1),
(2, 2),
) == 2 |
benchmark_functions_edited/f1879.py | def f(n):
if not input:
return 0
else:
return (n*(n+1))/2
assert f(0) == 0 |
benchmark_functions_edited/f9187.py | def f(s: str) -> int:
result = 0
for char in s:
if char.isalpha() or char.isdigit():
result += 1
return result
assert f(
"12345"
) == 5 |
benchmark_functions_edited/f13447.py | def f(obj, name, default=None):
while obj:
if hasattr(obj, 'params') and name in obj.params:
return obj.params[name]
elif hasattr(obj, 'parent'):
obj = obj.parent
else:
break
return default
assert f(None, 'a', 1) == 1 |
benchmark_functions_edited/f7006.py | def f(day_string):
translation_dictionary = {'Monday':0,'Tuesday':1, 'Wednesday':2, 'Thursday':3,'Friday':4,'Saturday':5,'Sunday':6}
return translation_dictionary[day_string]
assert f('Monday') == 0 |
benchmark_functions_edited/f1066.py | def f(x, a, b, c):
return a*x**2 + b*x + c
assert f(0, 1, 2, 3) == 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.