func_name stringlengths 2 57 | code stringlengths 206 31.2k | prompt stringlengths 12 1.86k | task_id stringlengths 1 5 | tests listlengths 5 5 | cyclomatic_complexity int64 10 82 |
|---|---|---|---|---|---|
toTextType |
class AvroNull:
pass
class AvroBoolean:
pass
class AvroInt:
pass
class AvroLong:
pass
class AvroFloat:
pass
class AvroDouble:
pass
class AvroBytes:
pass
class AvroString:
pass
class AvroArray:
def __init__(self, items):
self.items = items
class AvroMap:
def __in... | Render a type as humanreadable text. Note that this function is incomplete, but it covers all the cases seen in any PFA functions. | 1 | [
"def test_toTextType_0():\n assert toTextType(AvroNull()) == 'null'",
"def test_toTextType_1():\n assert toTextType(AvroNull()) == 'null'",
"def test_toTextType_2():\n assert toTextType(AvroNull()) == 'null'",
"def test_toTextType_3():\n assert toTextType(AvroNull()) == 'null'",
"def test_toText... | 11 |
protest | def protest(text,hashtag):
if (len(re.findall(r'\bmarch', text)) != 0) | (len(re.findall(r'\bprotest', text)) != 0) | (len(re.findall(r'\brally', text)) != 0) | (len(re.findall(r'\bgather', text)) != 0) | (len(re.findall(r'\bsit-in', text)) != 0) | (len(re.findall(r'\bcrowd', text)) != 0) | (len(re.findall(r'\briot... | boolean filter to be used in our classifier | 4 | [
"def test_protest_0():\n test_input = 'The protest march was peaceful and well-organized.'\n expected_output = 1\n assert protest(test_input, 'protest') == expected_output",
"def test_protest_1():\n test_input = 'A large crowd gathered for the rally, but no march was seen.'\n expected_output = 1\n ... | 21 |
paintTheFence | def paintTheFence(ranges, n, q):
section = [0] * (n + 2)
# Constant range addition
for i in range(q):
section[ranges[i][0]] += 1
# adding -1 to next idx to nullify the effect of addition
section[ranges[i][1]+1] -= 1
# prefix sum
for i in range(1, n + 1):
section[i]... | We first calculate all the sections that are painted by all the painters given and store them in sections array. This time we use the method of constant range addtion using prefix sums. | 7 | [
"def test_paintTheFence_0():\n assert paintTheFence([(1, 3), (2, 5)], 5, 2) == 2",
"def test_paintTheFence_1():\n assert paintTheFence([(1, 2), (2, 3), (3, 4)], 4, 3) == 1",
"def test_paintTheFence_2():\n assert paintTheFence([(1, 2), (2, 3), (3, 4), (1, 4)], 4, 4) == 0",
"def test_paintTheFence_3():... | 10 |
is_degree_in_degree_range | def is_degree_in_degree_range(degree_a, degree_b, degree_c):
degrees_omni = [degree_a, degree_b, degree_c]
for x in range(len(degrees_omni)):
if degrees_omni[x] > 180 or degrees_omni[x] <= -180:
degrees_omni[x] = -180 * (((degrees_omni[x] // 180) % 2) * degrees_omni[x]/abs(degrees_omni[x]))... | Checkes whether a given degreevalue lies between two bounding degreevalues, where degree_a and degree_b are the bounding degreelimits, with degree_a representing the clockwise oriented degreevalue and degree_b representing the counterclockwise degreevalue. Degree_c is the value being checked. | 10 | [
"def test_is_degree_in_degree_range_0():\n assert is_degree_in_degree_range(30, 150, 100) == True",
"def test_is_degree_in_degree_range_1():\n assert is_degree_in_degree_range(-190, 170, -180) == True",
"def test_is_degree_in_degree_range_2():\n assert is_degree_in_degree_range(359, 1, 180) == True",
... | 12 |
starve_nests |
terrain_nest_bc = 1
terrain_nest_sc = 2
terrain_nest_starved_bc = 3
bc_starve_range = 1
sc_feed_multiplier = 2
def starve_nests(terrain_map):
height = len(terrain_map)
width = len(terrain_map[0])
for y in range(height):
for x in range(width):
if terrain_map[y][x] == terrain_nest_bc:
... | For each BC, check other SC and BC tiles in a given range, and starve the nest if it then exceeds a limit set by sc_feed_multiplier | 13 | [
"def test_starve_nests_0():\n terrain_map = [[1, 1, 1, 1, 1], [1, 2, 2, 2, 1], [1, 2, 1, 2, 1], [1, 2, 2, 2, 1], [1, 1, 1, 1, 1]]\n expected_map = [[1, 1, 1, 1, 1], [1, 3, 2, 2, 1], [1, 2, 1, 2, 1], [1, 2, 2, 2, 1], [1, 1, 1, 1, 1]]\n result = starve_nests(terrain_map)\n assert result == expected_map, f... | 18 |
compute_comment_stats |
def compute_comment_stats(file_name, comment_char):
isComment = False
x = 0
try:
with open(file_name) as input:
idx = 0
for line in input:
isComment = False
while idx < (len(line) - 1):
if(comment_char == "#"):
... | Collect data on number of comments in the current file | 15 | [
"def test_compute_comment_stats_0():\n assert compute_comment_stats('test_comments.txt', '#') == 3",
"def test_compute_comment_stats_1():\n assert compute_comment_stats('test_no_comments.txt', '#') == 0",
"def test_compute_comment_stats_2():\n assert compute_comment_stats('test_multiple_comments.txt', ... | 14 |
question4c | def question4c(T, r, n1, n2):
# if three has less than three nodes, return None
if len(T)<=2:
return
# order search nodes
if n1<n2:
ln, rn = n1, n2
else:
ln, rn = n2, n1
while True:
# if either node matches with root, return root
if r==ln or r==ln:
... | Find the least common ancestor between two nodes on a binary search tree | 20 | [
"def test_question4c_0():\n test_input = [[], [1, 2, 3, 4, 5, 6, 7], 3, 5, 2, 4]\n assert question4c(*test_input) == 3",
"def test_question4c_1():\n test_input = [[], [1, 2, 3, 4, 5, 6, 7], 1, 5, 1, 5]\n assert question4c(*test_input) == 1",
"def test_question4c_2():\n test_input = [[], [1, 2, 3,... | 16 |
for_FIVE | def for_FIVE():
for row in range(5):
for col in range(4):
if col==0 and row!=3 or col==3 and row!=1 or row==0 or row==2 or row==4:
print("*",end=" ")
else:
print(" ",end=" ")
print() | printing numbr 'FIVE' using for loop | 21 | [
"def test_for_FIVE_0():\n for_FIVE()\n expected_output = ' * * * *\\n * * * *\\n * * * *\\n * * * *\\n * * * *'\n assert print('\\n'.join([''.join(line) for line in for_FIVE()]), f\"Expected output:\\n{expected_output}\\nBut got:\\n{''.join([''.join(line) for line in for_FIVE()])}\")",
"def test_for_FIVE... | 10 |
while_FIVE | def while_FIVE():
i=0
while i<5:
j=0
while j<4:
if i==0 or i==2 or i==4 or j==3 and i in(0,2,3,4)or j==0 and i==1:
print("*",end=" ")
else:
print(" ",end=" ")
j+=1
i+=1
prin... | printing number 'FIVE' using while loop | 22 | [
"def test_while_FIVE_0():",
"def test_while_FIVE_1():",
"def test_while_FIVE_2():",
"def test_while_FIVE_3():\n expected_output = ' ' * 25\n with self.assertRaises(SystemExit):\n while_FIVE()",
"def test_while_FIVE_4():"
] | 10 |
are_inputs_valid | def are_inputs_valid(mainParams, trgRoiNames):
mod = mainParams['roicolMod']
srcRoiName = mainParams['srcRoiName']
srcSlcNum = mainParams['srcSlcNum']
trgRoiName = mainParams['trgRoiName']
trgSlcNum = mainParams['trgSlcNum']
""" Useful variables:
RorS = 'ROI' or 'segment',
... | Check if the combination of input parameters are valid. | 28 | [
"def test_are_inputs_valid_0():\n test_input = {'roicolMod': 'RTSTRUCT', 'srcRoiName': 'TestROI', 'srcSlcNum': None, 'trgRoiName': 'TestROI', 'trgSlcNum': None, 'trgRoiNames': None}\n assert are_inputs_valid(test_input) == (True, '')",
"def test_are_inputs_valid_1():\n test_input = {'roicolMod': 'NIFTI',... | 14 |
get_edge_point_delta | def get_edge_point_delta(wd, ht, angle):
# logging.info(['angle: ', angle])
if angle >= 0 and angle <= math.pi/2: sector = 1
elif angle > math.pi/2: sector = 2
elif angle < -math.pi/2: sector = 3
elif angle <= 0 and angle >= -math.pi/2: sector = 4
# jfc have to define every single case separa... | get attach point of edge for node | 29 | [
"def test_get_edge_point_delta_0():\n assert get_edge_point_delta(10, 5, math.pi / 4) == (5, 5 * math.sqrt(2))",
"def test_get_edge_point_delta_1():\n assert get_edge_point_delta(10, 5, -math.pi / 4) == (5, -5 * math.sqrt(2))",
"def test_get_edge_point_delta_2():\n assert get_edge_point_delta(5, 10, ma... | 16 |
DetPiece |
def DetPiece(x):
wpawn = ['P'+str(i) for i in range(1, 9)]
bpawn = ['p'+str(i) for i in range(1, 9)]
wpromote = [None, 'Q', 'R', 'B', 'N']
bpromote = [None, 'q', 'r', 'b', 'n']
wother = ['R'+str(i) for i in range(1, 9)] + ['N'+str(i) for i in range(1, 9)] + ['B'+str(i) for i in range(1, 9)] + ['Q',... | Takes the starting location of the piece to be moved and returns a tuple that contains the name of the piece at that location and the boolean value of the color. Returns 'None' if there is nothing located at the given position | 30 | [
"def test_DetPiece_0():\n assert DetPiece('e4') == ('Pawn', True)",
"def test_DetPiece_1():\n assert DetPiece('e5') == ('Pawn', False)",
"def test_DetPiece_2():\n assert DetPiece('Nf3') == ('Knight', True)",
"def test_DetPiece_3():\n assert DetPiece('Qd1') == ('King', True)",
"def test_DetPiece_... | 18 |
get_adjacent_buckets | def get_adjacent_buckets(cx, cy, buckets):
c_bucket = []
b_length = len(buckets[0])
if cx - 1 >= 0:
c_bucket += buckets[cy ][cx - 1]
if cx - 1 >= 0 and cy - 1 >= 0:
c_bucket += buckets[cy - 1][cx - 1]
if cy - 1 >= 0:
c_bucket += buckets[cy - 1][cx]
if cx + 1 < b_leng... | Return a list of the points in the buckets adjacent to the given bucket. | 31 | [
"def test_get_adjacent_buckets_0():\n buckets = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n (cx, cy) = (1, 1)\n expected = [2, 4, 5, 6, 8, 9, 1, 3]\n assert get_adjacent_buckets(cx, cy, buckets) == expected",
"def test_get_adjacent_buckets_1():\n buckets = [[1, 2], [3, 4]]\n (cx, cy) = (0, 0)\n expec... | 13 |
for_three | def for_three():
for row in range(7):
for col in range(4):
if row%3==0 and col>0 and col<3 or col==3 and row%3!=0 or col==0 and row in (1,5):
print('*', end = ' ')
else:
print(' ... | Number pattern '3' using Python for loop | 35 | [
"def test_for_three_0():\n expected_output = ' * * *\\n * * *\\n * * *\\n * * *\\n * * *\\n * * *\\n * * *\\n'\n print(for_three())\n assert print(for_three()) == expected_output, 'Test failed: Output does not match expected pattern.'",
"def test_for_three_1():\n expected_output = ' * * *\\n * * *\\n ... | 10 |
while_three | def while_three():
row = 0
while row<7:
col = 0
while col<4:
if row%3==0 and col>0 and col<3 or col==3 and row%3!=0 or col==0 and row in (1,5):
print('*', end = ' ')
else:
... | Number pattern '3' using Python while loop | 36 | [
"def test_while_three_0():\n expected_output = ' * * *\\n * * *\\n * * *\\n * * *\\n * * *\\n * * *\\n * * *\\n'\n assert while_three() == expected_output",
"def test_while_three_1():\n expected_output = ' * * *\\n * * *\\n * * *\\n * * *\\n * * *\\n * * *\\n * * *\\n'\n assert while_three() == expect... | 10 |
do_filesizeformat | def do_filesizeformat(value, binary=False):
bytes = float(value)
base = binary and 1024 or 1000
prefixes = [
(binary and "KiB" or "kB"),
(binary and "MiB" or "MB"),
(binary and "GiB" or "GB"),
(binary and "TiB" or "TB"),
(binary and "PiB" or "PB"),
(b... | Format the value like a 'humanreadable' file size (i.e. 13 kB, 4.1 MB, 102 Bytes, etc). Per default decimal prefixes are used (Mega, Giga, etc.), if the second parameter is set to `True` the binary prefixes are used (Mebi, Gibi). | 38 | [
"def test_do_filesizeformat_0():\n assert do_filesizeformat(13) == '13 Bytes'",
"def test_do_filesizeformat_1():\n assert do_filesizeformat(0.5) == '0.5 Bytes'",
"def test_do_filesizeformat_2():\n assert do_filesizeformat(999999, False) == '999.999 kB'",
"def test_do_filesizeformat_3():\n assert d... | 23 |
region_initial_allocated_loss |
def region_initial_allocated_loss(m, r):
region_interconnector_loss = 0
for i in m['S_INTERCONNECTORS']:
from_region = m['P_INTERCONNECTOR_FROM_REGION'][i]
to_region = m['P_INTERCONNECTOR_TO_REGION'][i]
mnsp_status = m['P_INTERCONNECTOR_MNSP_STATUS'][i]
if r not in [from_regio... | Losses allocated to region due to interconnector flow | 39 | [
"def test_region_initial_allocated_loss_0():\n m = {'S_INTERCONNECTORS': [0], 'P_INTERCONNECTOR_FROM_REGION': ['A', 'B'], 'P_INTERCONNECTOR_TO_REGION': ['B', 'A'], 'P_INTERCONNECTOR_MNSP_STATUS': ['1', '0'], 'P_INTERCONNECTOR_INITIAL_LOSS_ESTIMATE': [100], 'P_INTERCONNECTOR_LOSS_SHARE': [0.1], 'P_INTERCONNECTOR_... | 19 |
region_allocated_loss_rule |
def region_allocated_loss_rule(m, r):
region_interconnector_loss = 0
for i in m['S_INTERCONNECTORS']:
from_region = m['P_INTERCONNECTOR_FROM_REGION'][i]
to_region = m['P_INTERCONNECTOR_TO_REGION'][i]
mnsp_status = m['P_INTERCONNECTOR_MNSP_STATUS'][i]
if r not in [from_region, t... | Interconnector loss allocated to given region | 40 | [
"def test_region_allocated_loss_rule_0():\n m = {'S_INTERCONNECTORS': [0], 'P_INTERCONNECTOR_FROM_REGION': ['A', 'B'], 'P_INTERCONNECTOR_TO_REGION': ['B', 'A'], 'P_INTERCONNECTOR_MNSP_STATUS': ['1', '0'], 'V_LOSS': [100], 'P_INTERCONNECTOR_LOSS_SHARE': [0.1], 'P_INTERCONNECTOR_EFFECTIVE_INITIAL_MW': [50, -10]}\n... | 19 |
max_size_for_tile | def max_size_for_tile(tile, grid, tile_by_loc, rclk_rows):
tile_type = grid[tile]['type']
if tile_type == 'NULL':
return (1, 1)
# Pos X, Neg Y
base_grid_x = grid[tile]['grid_x']
base_grid_y = grid[tile]['grid_y']
# Walk up X
grid_x = base_grid_x
grid_y = base_grid_y
while T... | Guess maximum size for a tile. | 41 | [
"def test_max_size_for_tile_0():\n test_input = {\n 'tile': 'A',\n 'grid': {\n 'A': {'type': 'NULL', 'grid_x': 0, 'grid_y': 0},\n 'B': {'type': 'NULL', 'grid_x': 1, 'grid_y': 0},\n 'C': {'type': 'NULL', 'grid_x': 2, 'grid_y': 0},\n 'D': {'type': 'NULL', '... | 10 |
create_process_env | def create_process_env(options):
penv = {}
## by default, a worker/guest process inherits
## complete environment
inherit_all = True
## check/inherit parent process environment
if 'env' in options and 'inherit' in options['env']:
inherit = options['env']['inherit']
if type(inhe... | Create worker process environment dictionary. | 42 | [
"def test_create_process_env_0():\n options = {'env': {'inherit': True, 'vars': {'PATH': '/usr/bin'}}}\n expected_env = os.environ.copy()\n expected_env['PATH'] = '/usr/bin'\n env = create_process_env(options)\n assert env == expected_env",
"def test_create_process_env_1():\n options = {'env': {... | 12 |
check_convert | def check_convert(original_string, target_string, n_operations):
len_original = len(original_string)
len_target = len(target_string)
similar_index = 0
#import pdb;pdb.set_trace()
flag = True
while flag:
#special cases
if n_operations > (len_original + len_target):
ret... | check if the original_string can be converted to target_string in n_operations | 43 | [
"def test_check_convert_0():\n assert check_convert('abc', 'ac', 1) == True",
"def test_check_convert_1():\n assert check_convert('abc', 'ac', 1) == True",
"def test_check_convert_2():\n assert check_convert('abc', 'ac', 1) == True",
"def test_check_convert_3():\n assert check_convert('abc', 'ac',... | 15 |
truncate_object | def truncate_object(obj, n_bytes, is_header=False):
if n_bytes > 0:
critical_headers = ["authorization", "content-type", "x-fuzzerest-state"]
for key in obj if isinstance(obj, dict) else range(len(obj)):
if isinstance(obj[key], (dict, list)):
truncate_object(obj[key], n_b... | Reduce the number of character bytes in obj by n_bytes. This is necessary to avoid rejected oversized requests. | 45 | [
"def test_truncate_object_0():\n test_input = {'authorization': 'Bearer valid_token', 'content-type': 'application/json', 'x-fuzzerest-state': 'some_state', 'data': 'This is some data that should be truncated because it exceeds the limit.'}\n expected_output = {'authorization': 'Bearer valid_token', 'content-... | 10 |
filterLocations | def filterLocations(locs, model):
# Possible to do list:
# - Is there a need to check if water level data matches MWL?
# - Should we combine multiple stations at same grid location?
for site in locs:
for site2 in locs:
if (locs[site]['enabled'] and locs[site2]['enabled'] and
locs... | Leaves only one measurement station enabled per grid location in the model configuration. Chooses the one with original coordinates closest to the grid location. | 46 | [
"def test_filterLocations_0():\n locs = {\n 'site1': {'enabled': True, 'if_indices': [1, 2], 'moved_distance': 0.5, 'if_orientation': 'U'},\n 'site2': {'enabled': True, 'if_indices': [1, 2], 'moved_distance': 0.3, 'if_orientation': 'V'},\n 'site3': {'enabled': True, 'if_indices': [1, 2], 'mo... | 10 |
choose_stat | def choose_stat(favored_stats, unfavored_stats=None, exclude=None):
favored = [f for f in favored_stats
if not exclude or f not in exclude]
unfavored = None
if unfavored_stats:
unfavored = [u for u in unfavored_stats
if not exclude or u not in exclude]
if not... | Select stats based on preference | 55 | [
"def test_choose_stat_0():\n assert choose_stat(['strength', 'agility'], exclude=['agility']) == 'strength' or 'agility'",
"def test_choose_stat_1():\n assert choose_stat(['strength', 'agility'], unfavored_stats=['intelligence'], exclude=['agility']) in ['strength', 'intelligence']",
"def test_choose_stat... | 12 |
primes_list_mem | def primes_list_mem(num, isprime=[3]):
if num < 2:
return []
if num > 2 * len(isprime) + 2:
def mapping(x):
return (x - 3)//2
first_new = 2 * len(isprime) + 3
isprime += [num for num in range(first_new, num + 1, 2)]
temp2 = int(math.sqrt(num)) + 1
f... | Returns list of Prime numbers | 56 | [
"def test_primes_list_mem_0():\n assert primes_list_mem(10) == [2, 3, 5, 7]",
"def test_primes_list_mem_1():\n assert primes_list_mem(1) == []",
"def test_primes_list_mem_2():\n assert primes_list_mem(29) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]",
"def test_primes_list_mem_3():\n assert primes_list... | 14 |
edits1 | def edits1(word):
letters = 'abcdefghijklmnopqrstuvwxyz'
splits = [(word[:i], word[i:]) for i in range(len(word) + 1)]
deletes = [L + R[1:] for L, R in splits if R]
transposes = [L + R[1] + R[0] + R[2:] for L, R in splits if len(R)>1]
replaces = [L + c + R[1:] for L, R in splits ... | All edits that are one edit away from `word`. | 65 | [
"def test_edits1_0():\n assert 'a' in edits1('a')\n assert 'abc' in edits1('abc')\n assert 'acb' in edits1('abc')\n assert 'abb' in edits1('abc')\n assert 'abc' in edits1('ab')\n assert 'ab' in edits1('a')\n assert 'ac' in edits1('a')\n assert 'ab' in edits1('b')\n assert 'ba' in edits1('... | 11 |
test_init |
class CoreWorkflow:
def __init__(self):
self.message = {"first_name": "John", "last_name": "Doe"}
self.data_format = "custom"
self.origin_url = "http://localhost:5000/data"
self.start_time = None
self.use_response = False
self.verify_certs = False
self.lfh_ex... | Tests CoreWorkflow.__init__ and the state transition. | 67 | [
"def test_test_init_0():\n workflow = CoreWorkflow()\n assert workflow.message == {'first_name': 'John', 'last_name': 'Doe'}\n assert workflow.data_format == 'custom'\n assert workflow.origin_url == 'http://localhost:5000/data'\n assert workflow.start_time is None\n assert workflow.use_response is... | 10 |
choose_fun_cov |
def choose_fun_cov(str_cov, is_grad=False):
def grad_cov_se():
pass
def cov_se():
pass
def grad_cov_matern32():
pass
def cov_matern32():
pass
def grad_cov_matern52():
pass
def cov_matern52():
pass
assert isinstance(str_cov, str)
asse... | It is for choosing a covariance function or a function for computing gradients of covariance function. | 69 | [
"def test_choose_fun_cov_0():\n fun_cov = choose_fun_cov('matern32', True)\n assert fun_cov == grad_cov_matern32",
"def test_choose_fun_cov_1():\n fun_cov = choose_fun_cov('se', False)\n assert fun_cov == cov_se",
"def test_choose_fun_cov_2():\n fun_cov = choose_fun_cov('matern52', True)\n ass... | 10 |
list_to_tran | def list_to_tran(list):
transcription = ""
for tran in list:
if tran[-3:] == "(0)":
transcription += tran[:-3]
elif tran[-4:] == "(0)-" or tran[-4:] == "(0).":
transcription += tran[:-4] + tran[-1]
elif tran[-1] == ")" or tran[-2:] == ")-" or tran[-2:] == ").":
... | Transform the list of predicted tags to a printable way | 76 | [
"def test_list_to_tran_0():\n assert list_to_tran(['(0)Hello', '(0)-World', 'Test', '(0).Done']) == 'Hello World Test Done'",
"def test_list_to_tran_1():\n assert list_to_tran(['(0)Python', '(0)-Programming', 'is', '(0).fun', 'and', '(0)-cool']) == 'Python Programming is fun and cool'",
"def test_list_to_... | 10 |
on_box_edge |
class Position:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def on_box_edge(position, xmin, xmax, ymin, ymax, zmin, zmax):
return ((((position.x == xmin or position.x == xmax)
and position.y >= ymin
and position.y <= ymax)
or (... | Detect whether a point is on the perimeter of a given rectangular prism | 87 | [
"def test_on_box_edge_0():\n test_input = Position(0, 0, 0)\n assert on_box_edge(test_input, -1, 1, -1, 1, -1, 1) == True",
"def test_on_box_edge_1():\n test_input = Position(1, 1, 1)\n assert on_box_edge(test_input, 0, 2, 0, 2, 0, 2) == True",
"def test_on_box_edge_2():\n test_input = Position(2... | 10 |
get_task_frame |
class State:
def __init__(self, drawer_position, drawer_opening, lid_position, box_position):
self.drawer_position = drawer_position
self.drawer_opening = drawer_opening
self.lid_position = lid_position
self.box_position = box_position
class Position:
def __init__(self, x, y, t... | Get a taskrelated frame (e.g. drawer, lid, table, etc.) for actions such as place | 88 | [
"def test_get_task_frame_0():\n state = State(Position(0, 0, 0), 5, Position(0, 0, 0), Position(0, 0, 0))\n position = Position(1, 1, 0)\n assert get_task_frame(state, position) == 'stack'",
"def test_get_task_frame_1():\n state = State(Position(0, 0, 0), 5, Position(0, 0, 0), Position(0, 0, 0))\n ... | 45 |
get_nearest_open_cell |
TRACK = 1
START = 2
GOAL = 3
def get_nearest_open_cell(environment, x_crash, y_crash, vx=0, vy=0, acceptable_cells=(TRACK, START, GOAL)):
# Record number of rows (lines) and columns in the environment
rows = len(environment)
cols = len(environment[0])
# Add expanded coverage for searching for nearest... | Locate the nearest open cell in order to handle crash scenario. Distance is calculated as the Manhattan distance. Start from the crash grid square and expand outward from there with a radius of 1, 2, 3, etc. | 90 | [
"def test_get_nearest_open_cell_0():\n environment = [[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 3, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]\n (x_crash, y_crash) = (2, 2)\n expected = (1, 1)\n assert get_nearest_open_cell(environment, x_crash, y_crash) == expected",
"def test_get_nearest_open_cell_1():\... | 13 |
get_one_move |
from enum import Enum
class Move(Enum):
ROCK = 1
PAPER = 2
SCISSORS = 3
class Result(Enum):
WIN = 1
LOSE = 2
DRAW = 3
def get_one_move(move2: Move, result: Result) -> Move:
if result == Result.DRAW:
return move2
if result == Result.LOSE:
if move2 == Move.ROCK:
... | Get Player 1's move given Player 2's move and the outcome. | 95 | [
"def test_get_one_move_0():\n assert get_one_move(Move.ROCK, Result.LOSE) == Move.SCISSORS",
"def test_get_one_move_1():\n assert get_one_move(Move.SCISSORS, Result.WIN) == Move.ROCK",
"def test_get_one_move_2():\n assert get_one_move(Move.PAPER, Result.LOSE) == Move.ROCK",
"def test_get_one_move_3()... | 10 |
merge_date_ranges | def merge_date_ranges(dates):
if not dates:
return
saved = list(dates[0])
for st, en in sorted([sorted(t) for t in dates]):
if st < MIN_PERIOD_DATE or st > MAX_PERIOD_DATE:
raise ValueError("start date %s is out of bounds" % str(st))
if en < MIN_PERIOD_DATE or en > MAX_... | Merge date ranges. Generator that merges ovelaped data ranges. Default init and end dates (19000101 and 21000101) are considered range | 103 | [
"def test_merge_date_ranges_0():\n dates = [[(19000101, 19000201), (19000201, 19000301)], [(19000201, 19000401)]]\n expected = [(19000101, 19000401)]\n result = list(merge_date_ranges(dates))\n assert result == expected, f'Expected {expected}, got {result}'",
"def test_merge_date_ranges_1():\n date... | 11 |
island_perimeter | def island_perimeter(grid):
perimeter = 0
if len(grid) < 100:
for list_num in range(len(grid) - 1):
if len(grid[list_num]) < 100:
for uno in range(len(grid[list_num]) - 1):
if grid[list_num][uno] != 0:
if list_num < len(grid) - 1:
... | returns the perimeter of the island described in grid | 113 | [
"def test_island_perimeter_0():",
"def test_island_perimeter_1():",
"def test_island_perimeter_2():",
"def test_island_perimeter_3():",
"def test_island_perimeter_4():"
] | 24 |
check_table_format | def check_table_format(table):
if not isinstance(table, dict):
sys.stderr.write("Backpointer table is not a dict.\n")
return False
for split in table:
if not isinstance(split, tuple) and len(split) ==2 and \
isinstance(split[0], int) and isinstance(split[1], int):
... | Return true if the backpointer table object is formatted correctly. Otherwise return False and print an error. | 121 | [
"def test_check_table_format_0():\n test_input = {(0, 1): {'S': ((0, 1, 2), (1, 2, 3))}, (1, 2): {'A': 'leaf'}}\n assert check_table_format(test_input) == True",
"def test_check_table_format_1():\n test_input = {(0, 1): {'S': ((0, 1, 2), (1, 2, 3))}, (1, 2): {'A': 'leaf'}}\n assert check_table_format(... | 19 |
check_probs_format | def check_probs_format(table):
if not isinstance(table, dict):
sys.stderr.write("Probability table is not a dict.\n")
return False
for split in table:
if not isinstance(split, tuple) and len(split) ==2 and isinstance(split[0], int) and isinstance(split[1], int):
sys.stderr.... | Return true if the probability table object is formatted correctly. Otherwise return False and print an error. | 122 | [
"def test_check_probs_format_0():\n test_input = {(0, 1): {'A': 0.5, 'B': 0.5}, (1, 2): {'A': 0.7, 'B': 0.3}}\n assert check_probs_format(test_input) == True",
"def test_check_probs_format_1():\n test_input = {(0, 1): {'A': 0.5, 'B': 0.5}, (1, 2): {'A': 0.7, 'B': 0.3}}\n assert check_probs_format(test... | 12 |
date_to_jd | def date_to_jd(year,month,day):
if month == 1 or month == 2:
yearp = year - 1
monthp = month + 12
else:
yearp = year
monthp = month
# this checks where we are in relation to October 15, 1582, the beginning
# of the Gregorian calendar.
if ((year < 1582) or
... | Convert a date to Julian Day. Algorithm from 'Practical Astronomy with your Calculator or Spreadsheet', 4th ed., DuffetSmith and Zwart, 2011. | 123 | [
"def test_date_to_jd_0():\n assert date_to_jd(2021, 3, 14) == 2459580.5",
"def test_date_to_jd_1():\n assert date_to_jd(1582, 10, 4) == 2299160.5",
"def test_date_to_jd_2():\n assert date_to_jd(2000, 1, 1) == 2451544.5",
"def test_date_to_jd_3():\n assert date_to_jd(2000, 12, 31) == 2451544.5",
... | 10 |
generate_suite_name |
class RunProperties:
def __init__(self, enterprise, encryption_at_rest=False, ssl=False):
self.enterprise = enterprise
self.encryption_at_rest = encryption_at_rest
self.ssl = ssl
def generate_suite_name(properties: RunProperties, versions: list, runner_type, installer_type):
ZIP_PACKAG... | generate test suite name for allure report | 124 | [
"def test_generate_suite_name_0():\n properties = RunProperties(enterprise=True, encryption_at_rest=True, ssl=True)\n versions = [1, 2, 3]\n runner_type = 'JUnit'\n installer_type = 'universal binary archive'\n assert generate_suite_name(properties, versions, runner_type, installer_type) == 'ArangoDB... | 10 |
_translate_binary_operator |
class Tree:
def __init__(self, token):
self.children = [token]
class Token:
def __init__(self, value):
self.value = value
def _translate_binary_operator(tree: Tree) -> str:
# Binary op will have only one child and it will be a Token
operator = tree.children[0]
if operator.value =... | Translates nonpython binary operators to python equivalents. | 125 | [
"def test__translate_binary_operator_0():\n tree = Tree(Token('gt'))\n assert _translate_binary_operator(tree) == ' > '",
"def test__translate_binary_operator_1():\n tree = Tree(Token('eq'))\n assert _translate_binary_operator(tree) == ' == '",
"def test__translate_binary_operator_2():\n tree = T... | 11 |
calculate_read_trim_position_linear | def calculate_read_trim_position_linear(read,
m,
alpha,
beta,
gamma,
offset,
bal... | This implements the linear version of the read trimmer. Read is a tuple. It has the id string, the read string, and the phred string. alpha controls the influence of the length beta controls the influence of the correctness probability gamma controls the influence of entropy balanced uses the geometric mean entropyOnly... | 126 | [
"def test\n ",
"def",
"",
"",
""
] | 14 |
for_j | def for_j():
for row in range(8):
for col in range(3):
if col==2 and row!=1 or row==7 and col in(1,2) or row in(6,5) and col!=1 or row==2 and col!=0:
print("*",end=" ")
else:
print(" ",end=" ")
print() | printing small 'j' using for loop | 128 | [
"def test_for_j_0():\n def test_for_j_0():\n test_for_j_0()",
"def test_for_j_1():\n def test_for_j_1():\n test_for_j_1()",
"",
"",
""
] | 11 |
quick_select | def quick_select(S, k):
if len(S) == 1:
return S[0]
pivot = random.choice(S) # pick random pivot element from S
L = [x for x in S if x < pivot] # elements less than pivot
E = [x for x in S if x == pivot] # elements equal to pivot
G = [x for x in S if x > pivot] # elements greater than p... | return the kth smallest element of list S, for k from 1 to len(S) | 130 | [
"def test_quick_select_0(S, k:",
"def test_quick_select_1():\n assert quick_select([3, 1, 2, 4, 5], 1) == 1",
"def test = 1\n assert 1\n [1\n assert\n assert\n assert\n # 1\n assert\n # 1\n # 1\n # 1\n # 1\n # 1\n # 1\n # 1\n # 1\n # 1\n # 1\n # 1\n # ... | 10 |
Lgain | def Lgain(spacecraft_id, sensor_id, band_id):
if(spacecraft_id == "Terra"):
if (sensor_id == "Aster"):
if(band_id == "band1"):
Lgain = 0.676
if(band_id == "band2"):
Lgain = 0.862
if(band_id == "band3"):
Lgain = 0.217
if(band_id == "band4"):
Lgain = 0.0696
if(band_id == "band5"):
Lg... | Gain for Dn to Rad conversion This is used for processing radiance of Terra Aster images. | 135 | [
"def test_Lgain:\n def test_Lgain:\n def test_Lgain:\n\tspacecraft = 0.0.0:\n test_Lgain:\n\tdef test_Lgain:\n test_L:\n\t0.0:\n\t0.0:\n\t0.0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:... | 11 |
Loffset | def Loffset(spacecraft_id, sensor_id, band_id):
if(spacecraft_id == "Terra"):
if (sensor_id == "Aster"):
if(band_id == "band1"):
Loffset = -0.676
if(band_id == "band2"):
Loffset = -0.862
if(band_id == "band3"):
Loffset = -0.217
if(band_id == "band4"):
Loffset = -0.0696
if(band_id == "b... | Offset for Dn to Rad conversion This is used for processing radiance of Terra Aster images. | 136 | [
"def test_Loffset_0:\n def test_Loffset_0:\n def test_Loffset_0:\n\tspacecraft_id = 0.0.0:\n def test_Loffset_0(spacecraft = 0:\n test_Loffset_0 = 0:\n if 0:\n if 0:\n if 0:\n if 0:\n if 0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t0:\n\t... | 11 |
log_quadrature_rule | def log_quadrature_rule(N_poly, N_poly_log):
lvls = (N_poly, N_poly_log)
if lvls == (0, 0):
return ((0.36787944117144232159552377016146086744581, ),
((1.00000000000000000000000000000000000000000, )))
elif lvls == (1, 1):
return ((
0.0882968651376530117595951385184... | Returns quadrature rule that is exact on 0^1 for p(x) + q(x)log(x) for deg(p) <= N_poly and deg(q) <= N_log. | 140 | [
"def test_log_quadrature_rule_0():\n # Test cases for the log_quadrature_rule function\n # Each test case is a tuple of (N_poly, N_log, expected_rule)\n test_cases = [\n (0, 0, (0.0, 0.0)), # No polynomial or logarithm, trivial case\n (1, 0, (0.0, 0.0)), # Linear polynomial, no logarithm\n ... | 32 |
log_log_quadrature_rule | def log_log_quadrature_rule(N_poly, N_log):
lvls = (N_poly, N_log)
if lvls == (0, 0):
return ((
0.061151359021200679621983711149640788306168520381328374043636166,
0.500000000000000000000000000000000000000000000000000000000000000,
0.938848640978799320378016288850359211... | Returns quadrature rule that is exact on 0^1 for p(x) + q(x)log(x) + k(x)log(1x) for deg(p) <= N_poly, deg(k) <= deg(q) <= N_log. | 141 | [
"def test_log_log_quadrature_rule_0():",
"def test_log_log_quadrature_rule_1():",
"def test_log_log_quadrature_rule_2():",
"def test_log_log_quadrature_rule_3():",
"def test_log_log_quadrature_rule_4():"
] | 18 |
sqrtinv_quadrature_rule | def sqrtinv_quadrature_rule(N_poly, N_poly_sqrt):
lvls = (N_poly, N_poly_sqrt)
if lvls == (0, 0):
return ((0.25, ), (1., ))
elif lvls == (1, 1):
return ((
0.0446581987385204510787589430823546055095,
0.6220084679281462155879077235843120611571,
), (
... | Returns quadrature rule that is exact on 0^1 for p(x) + q(x)1/sqrt(x) for deg(p) <= N_poly and deg(q) <= N_poly_sqrt. | 143 | [
"def test_sqrtinv_quadrature_rule_0():\n assert sqrtinv_quadrature_rule(0, 0) == ((0.25,), (1.0,))",
"def test_sqrtinv_quadrature_rule_1():",
"def test_sqrtinv_quadrature_rule_2():",
"def test_sqrtinv_quadrature_rule_3():",
"def test_sqrtinv_quadrature_rule_4():"
] | 16 |
gauss_sqrtinv_quadrature_rule | def gauss_sqrtinv_quadrature_rule(N):
if N == 1:
return ((0.3333333333333333333333333333333333333333333, ),
(2.0000000000000000000000000000000000000000000, ))
elif N == 2:
return ((
0.1155871099970479351674458383995416377412887,
0.7415557471458092076896970... | Gauss rule of N pts that is exact on 0^1 with weight sqrt(x)^1 | 144 | [
"def test_gauss_sqrtinv_quadrature_rule_0():",
"def test_gauss_sqrtinv_quadrature_rule_1():\n assert gauss_sqrtinv_quadrature_rule(4) == ((0.022163568807217638, 0.18783156765244552, 0.46159736149626673, 0.7483346283872805, 0.9484939262883686), (0.5910484494295057, 0.5385334386199927, 0.4381727250319641, 0.2989... | 14 |
End of preview. Expand in Data Studio
No dataset card yet
- Downloads last month
- 59