file_name
stringlengths 32
36
| content
stringlengths 44
898
|
|---|---|
benchmark_functions_edited/f3956.py
|
def f(key):
sections = {'queue': 1, 'jobs': 2, 'jobqueue': 3}
return sections[key]
assert f('jobs') == 2
|
benchmark_functions_edited/f11524.py
|
def f(message, log_file):
with open(log_file, "a") as file_handle:
message.rstrip()
file_handle.write(message+"\n")
return 0
assert f("Fourth test", "test_file.txt") == 0
|
benchmark_functions_edited/f3973.py
|
def f(separators):
num_blocks = len(separators) + 1
assert num_blocks >= 2
return num_blocks
assert f(set([4])) == 2
|
benchmark_functions_edited/f11771.py
|
def f(list_of_karyotypes):
stable_count = 0
for kary_group in list_of_karyotypes:
if ''.join(kary_group).count('0') == 4 * 6:
stable_count += 1
return stable_count
assert f(
[list("000000"), list("101010"), list("0111110"), list("000000"),
list("000000"), list("000000"), list("000000"), list("000000")]) == 0
|
benchmark_functions_edited/f10024.py
|
def f(sort_data):
count_1 = 0
sum_precision = 0
for index in range(len(sort_data)):
if sort_data[index][1] == 1:
count_1 += 1
sum_precision += 1.0 * count_1 / (index + 1)
return sum_precision / count_1
assert f(
[(3, 1), (4, 1), (2, 1), (1, 1), (0, 1)]) == 1
|
benchmark_functions_edited/f10639.py
|
def f(integer_string, strict=False, cutoff=None):
if integer_string:
ret = int(integer_string)
else:
return integer_string
if ret == 0 and strict:
raise ValueError()
if cutoff:
return min(ret, cutoff)
return ret
assert f('1') == 1
|
benchmark_functions_edited/f8218.py
|
def f(f, h):
fm3, fm2, fm1, f1, f2, f3 = [f(i*h) for i in [-3, -2, -1, 1, 2, 3]]
fp = (f3-9*f2+45*f1-45*fm1+9*fm2-fm3)/(60*h)
return fp
assert f(lambda x: 1, 1e-10) == 0
|
benchmark_functions_edited/f10508.py
|
def f(freqint,nk):
if freqint>=0:
return freqint
else:
return nk + freqint
# end if
assert f(-1,4) == 3
|
benchmark_functions_edited/f8168.py
|
def f(lhs, rhs):
lhs_sorted = sorted(lhs, key=lambda x:sorted(x.keys()))
rhs_sorted = sorted(rhs, key=lambda x:sorted(x.keys()))
return (lhs_sorted > rhs_sorted) - (lhs_sorted < rhs_sorted)
assert f(dict(), dict()) == 0
|
benchmark_functions_edited/f12052.py
|
def f(review_comments, user):
return sum(1 for review_comment in review_comments
# In obsolote comments, the position is None
if review_comment['position'] and
review_comment['user']['login'] == user)
assert f([{'user': {'login': 'bob'}, 'position': 12345678}], 'bob') == 1
|
benchmark_functions_edited/f1390.py
|
def f(phasefilt, mtffilt):
filt = phasefilt * mtffilt
return filt
assert f(0,0) == 0
|
benchmark_functions_edited/f12051.py
|
def f(t):
if t is None:
return 0
else:
return 1 + max(f(t.left), f(t.right))
assert f(None) == 0
|
benchmark_functions_edited/f14025.py
|
def f(delT):
### BEGIN SOLUTION
c = 3e8 #speed of light (m/s)
delT = delT*(1.e-6) #convert microseconds to s
radar_range = c*delT/2
return radar_range*1.e-3
assert f(0) == 0
|
benchmark_functions_edited/f3021.py
|
def f(matrix):
return min(set([len(vals) for vals in matrix.values()]))
assert f(
{
"a": ["a"],
"b": ["b"]
}) == 1
|
benchmark_functions_edited/f8498.py
|
def f(nums):
l, r = 0, len(nums) - 1
while nums[l] > nums[r]:
m = (l + r) // 2
if nums[m] > nums[r]:
l = m + 1
elif nums[m] < nums[r]:
r = m
return nums[l]
assert f([4, 5, 3, 2, 1]) == 1
|
benchmark_functions_edited/f304.py
|
def f(arr):
return sum(arr) / len(arr) if arr else None
assert f( [ 1, 2, 3 ] ) == 2
|
benchmark_functions_edited/f5879.py
|
def f(*k_values):
result = 1
for i, j in enumerate((m for k in k_values for m in range(1, k+1)), 1):
result = (result * i) // j
return result
assert f(0, 0, 0) == 1
|
benchmark_functions_edited/f4968.py
|
def f(token):
if token.isnumeric():
return int(token)
try:
return float(token)
except:
return token
assert f("0") == 0
|
benchmark_functions_edited/f8314.py
|
def f(old, new):
if old is None:
return new
if new is None:
return old
return old + new
assert f(None, 1) == 1
|
benchmark_functions_edited/f1635.py
|
def f(arr1, arr2):
return len(set(arr1 + arr2))
assert f( [1, 2, 3], [] ) == 3
|
benchmark_functions_edited/f1457.py
|
def f(page, per_page):
return per_page * (page + 1)
assert f(3, 1) == 4
|
benchmark_functions_edited/f6610.py
|
def f(metadata, key):
try:
metadata.__delitem__(key)
except KeyError:
print(("There's not a %s tag in this image, exiting..." % key))
return 1
assert f(
{"tag1": "foo", "tag2": "bar"},
"tag3",
) == 1
|
benchmark_functions_edited/f13626.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 # + 1 is for the space
return char_offset
assert f(
{"long_answer_candidates": [{"start_token": 0, "end_token": 10}],
"document_tokens": [{"token": "foo", "html_token": False}, {"token": " ", "html_token": False}, {"token": "bar", "html_token": False}]},
0, 0) == 0
|
benchmark_functions_edited/f1229.py
|
def f(kinetic, N, kb, T, Q):
G = (2*kinetic - 3*N*kb*T)/Q
return G
assert f(0, 0, 0, 0, 1) == 0
|
benchmark_functions_edited/f13638.py
|
def f(n, odd_term, even_term):
"*** YOUR CODE HERE ***"
total, k = 0, 1
while k <= n:
if k % 2 == 0:
total, k = total + even_term(k), k + 1
else:
total, k = total + odd_term(k), k + 1
return total
assert f(2, lambda x: x, lambda x: x * x) == 5
|
benchmark_functions_edited/f5897.py
|
def f(indices_size, index):
if indices_size < 1:
raise ValueError("The tensor's index is unreasonable. index:{}".format(index))
return indices_size
assert f(1, [0]) == 1
|
benchmark_functions_edited/f5412.py
|
def f(config):
return config.get('CONFIG_VERSION', {}).get('CURRENT', 0)
assert f(dict()) == 0
|
benchmark_functions_edited/f6926.py
|
def f(m: int, n: int) -> int:
if m == 0:
return n + 1
elif n == 0:
return f(m - 1, 1)
else:
return f(m - 1, f(m, n - 1))
assert f(2, 0) == 3
|
benchmark_functions_edited/f12371.py
|
def f(func, lo, hi):
while lo <= hi:
lo_third = lo + (hi - lo) // 3
hi_third = lo + (hi - lo) // 3 + (1 if 0 < hi - lo < 3 else (hi - lo) // 3)
if func(lo_third) < func(hi_third):
lo = lo_third + 1
else:
hi = hi_third - 1
return lo
assert f(lambda x: 2, 0, 0) == 0
|
benchmark_functions_edited/f1000.py
|
def f(dividend, divisor):
return -(-dividend // divisor)
assert f(13, 3) == 5
|
benchmark_functions_edited/f11806.py
|
def f(i, j, k, o):
test_set = set((i, j, k, o))
if not (test_set <= set((1, 2, 3, 4)) or test_set <= set((0, 1, 2, 3))):
raise Exception("Unexpected input", i, j, k, o)
return (i - j) * (j - k) * (k - i) * (i - o) * (j - o) * (o - k) / 12
assert f(1, 1, 1, 0) == 0
|
benchmark_functions_edited/f740.py
|
def f(iterable):
return next(iter(iterable))
assert f(iter(range(9, 100))) == 9
|
benchmark_functions_edited/f13655.py
|
def f(value):
if isinstance(value, list):
if len(value) == 1 and isinstance(value[0], dict) and "@value" in value[0]:
return value[0]["@value"]
return [f(v) for v in value]
if isinstance(value, dict):
if "@value" in value:
return value["@value"]
else:
return {k: f(v) for k, v in value.items()}
return value
assert f({"@value": 1}) == 1
|
benchmark_functions_edited/f12348.py
|
def f(ports):
web = 0
smb = 0
# Determine if we ports open
if (('80' in ports) or ('443' in ports)):
web = 1
# Determine if SMB ports open
if (('139' in ports) or ('445' in ports)):
smb = 2
return web + smb
assert f(set(['80', '443'])) == 1
|
benchmark_functions_edited/f226.py
|
def f(p, q):
return ((p - 1) * (q - 1))
assert f(2, 3) == 2
|
benchmark_functions_edited/f5346.py
|
def f(num_list):
if not num_list:
return 0.0
else:
return sum(num_list) / float(len(num_list))
assert f([1]) == 1
|
benchmark_functions_edited/f2856.py
|
def f(page):
try:
rv = int(page)
except (ValueError, TypeError):
rv = 1
return rv
assert f('3') == 3
|
benchmark_functions_edited/f6423.py
|
def f(itr):
try:
return min(itr)
except ValueError:
return None
assert f([3, 5, 1, 4, 2]) == 1
|
benchmark_functions_edited/f6060.py
|
def f(value, another):
# Do something with these values
# and more comment text, here.
#
if value:
return 2
# Another comment
return 1
assert f(False, None) == 1
|
benchmark_functions_edited/f8513.py
|
def f(taxid, tree, stop_nodes):
t = taxid
while True:
if t in stop_nodes:
return t
elif not t or t == tree[t]:
return t # root
else:
t = tree[t]
assert f(1, {1:2, 2:4, 3:5}, {3, 4, 5}) == 4
|
benchmark_functions_edited/f8916.py
|
def f(arr):
lo, hi = -1, len(arr)-1 # left open & right close
while lo < hi:
mid = lo + hi + 1 >> 1
if arr[mid]: lo = mid
else: hi = mid - 1
return lo
assert f([1]) == 0
|
benchmark_functions_edited/f8497.py
|
def f(p0, p1):
return ((p1[0] - p0[0])**2 + (p1[1] - p0[1])**2)**(1/2)
assert f( (0, 0), (0, 0) ) == 0
|
benchmark_functions_edited/f2639.py
|
def f(generator):
counter = 0
for _ in generator:
counter += 1
return counter
assert f(range(2, 10)) == 8
|
benchmark_functions_edited/f4051.py
|
def f(value, index):
# NOTE: We could also use int.to_bytes to just convert
# value into a byte array.
return value >> index * 8 & 0xFF
assert f(12, 2) == 0
|
benchmark_functions_edited/f8349.py
|
def f(n):
if n == 0:
return 0
if n == 1:
return 1
else:
return n * f(n - 2)
assert f(0) == 0
|
benchmark_functions_edited/f7657.py
|
def f(n):
count = 0
start = 5
for i in range(0,n):
count =count + start/2
start = (start/2)*3
return count
assert f(0) == 0
|
benchmark_functions_edited/f14502.py
|
def f(repo, blacklist):
errors = 0
if len(repo.get("description", "")) < 10:
print("ERROR! openeuler/" + repo["name"] + "\'s description is too short.")
errors += 1
if repo["name"] in blacklist:
print("ERROR! openeuler/" + repo["name"] + " was black-listed.")
print(" Because: " + blacklist[repo["name"]])
errors += 1
return errors
assert f(
{
"name": "aaa",
"description": "a"*10
},
{
"bbb": "reason",
"ccc": "reason"
}
) == 0
|
benchmark_functions_edited/f11509.py
|
def f(n , show= False):
f = 1
for c in range(n, 0, -1):
f *= c
if show:
print(f'{c}', 'x' if c != 1 else '=', end=' ')
return f
assert f(3) == 6
|
benchmark_functions_edited/f5171.py
|
def quadratic_model ( p, agdd ):
return p[0]*agdd**2 + p[1]*agdd + p[2]
assert f( [0,0,0], 3 ) == 0
|
benchmark_functions_edited/f327.py
|
def f(n):
return int(n * (n + 1) / 2)
assert f(2) == 3
|
benchmark_functions_edited/f1224.py
|
def f(values):
return sum(values) / float(len(values))
assert f([0, 1, 2, 3, 4]) == 2
|
benchmark_functions_edited/f11461.py
|
def f(li):
high, low = max(li), min(li)
for x in li:
if x != low and x != high:
return li.index(x)
assert f( [2, 3, 1] ) == 0
|
benchmark_functions_edited/f4637.py
|
def f(rankx, ranky):
return float(ranky - rankx)
assert f(12, 12) == 0
|
benchmark_functions_edited/f9877.py
|
def f(string):
from zlib import crc32
return crc32(string) & 0xffffffff
assert f(b"") == 0
|
benchmark_functions_edited/f13246.py
|
def f(nums):
max_sub_array = 0
sum = 0
for num in nums:
sum = max(0, sum + num)
max_sub_array = max(max_sub_array, sum)
if max_sub_array <= 0:
return max(nums)
return max_sub_array
assert f([-1, 2]) == 2
|
benchmark_functions_edited/f6673.py
|
def f(p: str):
if p == 'No bug': return 0
if p == 'Trivial': return 1
if p == 'Minor': return 2
if p == 'Blocker': return 3
if p == 'Major': return 4
if p == 'Critical': return 5
assert f('Critical') == 5
|
benchmark_functions_edited/f1739.py
|
def f(obj):
try:
return obj.__sizeof__()
except:
return 0
assert f(type) == 0
|
benchmark_functions_edited/f8801.py
|
def f(oid):
# Initialize key variables
nodes = oid.split('.')
value = int(nodes[-2])
# Return
return value
assert f('1.3.6.1.4.1.14988.1.1.2.2') == 2
|
benchmark_functions_edited/f303.py
|
def f(n):
return n if n >= 0 else n * -1
assert f(-5) == 5
|
benchmark_functions_edited/f11131.py
|
def f(dna, nucleotide):
count = 0
for letter in dna:
if letter == nucleotide:
count += 1
return count
assert f('', 'C') == 0
|
benchmark_functions_edited/f8123.py
|
def f(value, min_value, max_value):
scaled_value = min_value + int(value * (max_value - min_value + 1))
return scaled_value if scaled_value <= max_value else max_value
assert f(0.3, 1, 2) == 1
|
benchmark_functions_edited/f1413.py
|
def f(num, offset):
mask = 1 << offset
return num | mask
assert f(1, 1) == 3
|
benchmark_functions_edited/f10183.py
|
def f(a, b):
if a and b:
return (a**(-1) + b**(-1))**(-1)
else:
return 0
assert f(0, 1) == 0
|
benchmark_functions_edited/f2952.py
|
def f(v):
return v[0]*v[0] + v[1]*v[1] + v[2]*v[2]
assert f( [1,-1,1] ) == 3
|
benchmark_functions_edited/f4059.py
|
def f(generator, consume=False):
if consume:
for item in generator:
pass
return
return next(generator)
assert f((i for i in range(5))) == 0
|
benchmark_functions_edited/f13150.py
|
def f(args, kwargs, name):
try:
return kwargs[name]
except KeyError:
try:
return args[0]
except IndexError:
return None
assert f((), {"a": 1}, "a") == 1
|
benchmark_functions_edited/f8818.py
|
def f(source, path_):
parts = path_.split("[")
p_ = parts[0]
index = int(parts[1][:-1])
value = source.get(p_, None)
if value is None:
return value
try:
return value[index]
except IndexError:
return None
assert f({"a": [1, 2]}, "a[1]") == 2
|
benchmark_functions_edited/f13616.py
|
def f(N, x, array):
lower = 0
upper = N
while (lower + 1) < upper:
mid = int((lower + upper) / 2)
if x < array[mid]:
upper = mid
else:
lower = mid
if array[lower] <= x:
return lower
return -1
assert f(3, 1, [1, 2, 3]) == 0
|
benchmark_functions_edited/f5415.py
|
def f(ring):
if ring == 0:
return 1
else:
return ring * 2
assert f(1) == 2
|
benchmark_functions_edited/f5795.py
|
def f(byte_string) -> int:
return int.from_bytes(byte_string, "big")
assert f(b'\x00\x00\x00\x03') == 3
|
benchmark_functions_edited/f10916.py
|
def f(kwargs, name, default=None):
val = kwargs.get(name)
if val is None:
val = default
return val
assert f(dict(), 'a', 2) == 2
|
benchmark_functions_edited/f12043.py
|
def f(param):
try:
num = int(param)
except ValueError:
try:
num = float(param)
except ValueError:
num = str.encode(param)
return num
assert f(1) == 1
|
benchmark_functions_edited/f2205.py
|
def f(n, sigma):
a = sigma ** 2 / (float(n) + sigma ** 2)
return 1 - a
assert f(10, 0) == 1
|
benchmark_functions_edited/f12491.py
|
def f(depths):
depth_increases = 0
previous_depth = depths[0]
for depth in depths:
if depth > previous_depth:
depth_increases += 1
previous_depth = depth
return depth_increases
assert f(
[199, 200, 208, 210, 200, 207, 240, 269, 260, 263]
) == 7
|
benchmark_functions_edited/f11079.py
|
def f(text, substring, starting=0):
search_in = text[starting:]
if substring in search_in:
return search_in.index(substring)
else:
return -1
assert f('hello', 'lo') == 3
|
benchmark_functions_edited/f7462.py
|
def f(current_step, total_steps, steps_per_loop):
if steps_per_loop <= 0:
raise ValueError('steps_per_loop should be positive integer.')
return min(total_steps - current_step, steps_per_loop)
assert f(0, 10, 4) == 4
|
benchmark_functions_edited/f5712.py
|
def f(x, in_min, in_max, out_min, out_max):
return int(
(x - in_min) * (out_max - out_min)
//
(in_max - in_min) + out_min
)
assert f(-10, -10, 0, 0, 100) == 0
|
benchmark_functions_edited/f8181.py
|
def f(x):
if x <= 0:
return 0
num_twos = 0
while x % 2 == 0:
num_twos += 1
x //= 2
return num_twos
assert f(20) == 2
|
benchmark_functions_edited/f9039.py
|
def f(a_tag):
a_tag = a_tag.lower()
if a_tag == "positive":
return 1
elif a_tag == "negative":
return 0
return int(a_tag)
assert f(*("0",)) == 0
|
benchmark_functions_edited/f14473.py
|
def f(r, l, k):
r0 = (r - l) / (1 - k)
return r0
assert f(10, 10, 0.5) == 0
|
benchmark_functions_edited/f11703.py
|
def f(runs):
was_run_successful = lambda x: 1 if x['fail'] == 0 and x['pass'] > 0 else 0
successful_runs = map(was_run_successful, runs)
return sum(successful_runs)
assert f(
[
{'fail': 0, 'pass': 0},
{'fail': 0, 'pass': 1},
{'fail': 0, 'pass': 0},
]
) == 1
|
benchmark_functions_edited/f7243.py
|
def f(mc):
mc_min, mc_max = 0., 40.
if (mc >= mc_min) and (mc <= mc_max):
return 1
else:
return 0
assert f(40) == 1
|
benchmark_functions_edited/f12197.py
|
def f(size, numbers):
sum_nums = 0
for element in numbers:
sum_nums += int(element)
res = round(sum_nums/size,1)
return res
assert f(5, [1, 1, 1, 1, 1]) == 1
|
benchmark_functions_edited/f2302.py
|
def f(t: int, r: int = 3):
return round(t, r)
assert f(1, -1) == 0
|
benchmark_functions_edited/f7608.py
|
def f(paper):
counter = 0
for row in paper:
for dot in row:
if dot:
counter += 1
return counter
assert f(
[[True, False, False],
[False, False, False],
[False, False, False]]) == 1
|
benchmark_functions_edited/f11585.py
|
def f(temperature):
temperature += 273.15
if 20 <= temperature <= 800:
return 54 - 0.0333 * temperature
elif 800 <= temperature <= 1200:
return 27.3
else:
return 0
assert f(1000) == 0
|
benchmark_functions_edited/f9174.py
|
def f(x):
dizionario_limite = {'BENZENE': 5,
'NO2': 200,
'O3': 180,
'PM10': 50,
'PM2.5': 25}
return dizionario_limite[x]
assert f('BENZENE') == 5
|
benchmark_functions_edited/f736.py
|
def f(x: float) -> float:
return x ** (4 / 3) / float(x)
assert f(1) == 1
|
benchmark_functions_edited/f14320.py
|
def f(n):
"*** YOUR CODE HERE ***"
length = 1
while n != 1:
print(n)
if n % 2 == 0:
n = n // 2 # Integer division prevents "1.0" output
else:
n = 3 * n + 1
length = length + 1
print(n) # n is now 1
return length
assert f(10) == 7
|
benchmark_functions_edited/f14221.py
|
def f(samples, inputs, outputs, scaling_factor=2):
return int(round(samples / (scaling_factor * (inputs + outputs))))
assert f(20, 5, 4) == 1
|
benchmark_functions_edited/f13925.py
|
def f(num: int) -> int:
string_num = str(num)
count: int = 0
while len(string_num) > 1:
result = 1
for i in string_num:
result *= int(i)
string_num = str(result)
count += 1
return count
assert f(4) == 0
|
benchmark_functions_edited/f6314.py
|
def f(K, mode):
if mode == 'valid':
return 0
elif mode == 'same':
assert K % 2 == 1, 'Invalid kernel size %d for "same" padding' % K
return (K - 1) // 2
assert f(1, 'valid') == 0
|
benchmark_functions_edited/f9373.py
|
def f(val, src, dst):
return (float(val - src[0]) / (src[1] - src[0])) * (dst[1] - dst[0]) + dst[0]
assert f(99, (0, 99), (-1, 1)) == 1
|
benchmark_functions_edited/f1424.py
|
def f(i):
try:
return int(i)
except:
return i
assert f(1e-1) == 0
|
benchmark_functions_edited/f882.py
|
def f(values):
return sum(values) / len(values)
assert f([1, 2, 3]) == 2
|
benchmark_functions_edited/f3868.py
|
def f(path, data):
fragments = path.split(".")
src = data
for p in fragments:
src = src.get(p, {})
return src
assert f("a.b.c", {"a": {"b": {"c": 1}}}) == 1
|
benchmark_functions_edited/f441.py
|
def f(x,y):
return abs(x-y)/((abs(x)+abs(y))/2)
assert f(10, 10) == 0
|
benchmark_functions_edited/f9311.py
|
def f(length: int, block: int) -> int:
if length <= 0:
raise ValueError("The length must be positive")
return (length - 1) // block + 1
assert f(10, 3) == 4
|
benchmark_functions_edited/f4903.py
|
def f(theta, vmin, vmax):
return (theta - vmin) / (vmax - vmin)
assert f(0, 0, 1000) == 0
|
benchmark_functions_edited/f13886.py
|
def f(x):
#note: follows basic formula
#see: `calc_gini2`
#contact: aisaac AT american.edu
x = sorted(x) # increasing order
n = len(x)
G = sum(xi * (i+1) for i,xi in enumerate(x))
G = 2.0*G/(n*sum(x)) #2*B
return G - 1 - (1./n)
assert f([-1]) == 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.