Skip to content

Commit

Permalink
update: add data pack
Browse files Browse the repository at this point in the history
  • Loading branch information
terryyz committed May 18, 2024
1 parent 738fdbd commit 3634448
Show file tree
Hide file tree
Showing 54 changed files with 1,328 additions and 1,272 deletions.
2 changes: 1 addition & 1 deletion data/clean/f_243_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TestCases(unittest.TestCase):

def setUp(self):
# Set up the test file path
self.temp_dir = tempfile.gettempdir()
self.temp_dir = tempfile.mkdtemp()
self.test_file_path = f"{self.temp_dir}/test_log.json"

def tearDown(self):
Expand Down
6 changes: 5 additions & 1 deletion data/clean/f_245_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def f_1238(obj_list, attr, num_bins=30, seed=0):
class TestCases(unittest.TestCase):
def test_case_1(self):
# Input 1: Simple list of objects with integer values from 0 to 9
random.seed(1)
obj_list = [Object(value=i) for i in range(10)]
ax = f_1238(obj_list, 'value')

Expand All @@ -73,6 +74,7 @@ def test_case_1(self):

def test_case_2(self):
# Input 2: List of objects with random Gaussian values
random.seed(2)
obj_list = [Object() for _ in range(100)]
ax = f_1238(obj_list, 'value', seed=77)

Expand All @@ -83,10 +85,11 @@ def test_case_2(self):
self.assertEqual(ax.get_ylabel(), 'Count', "Y-axis label is incorrect.")
self.assertEqual(sum([p.get_height() for p in ax.patches]), len(obj_list), "Histogram data points do not match input list size.")
# Check axis data
self.assertAlmostEqual(ax.get_xlim()[0], -2.57, delta=0.1, msg="X-axis lower limit is incorrect.")
self.assertAlmostEqual(ax.get_xlim()[0], -3.933336166652307, delta=0.1, msg="X-axis lower limit is incorrect.")

def test_case_3(self):
# Input 3: List of objects with fixed value
random.seed(3)
obj_list = [Object(value=5) for _ in range(50)]
ax = f_1238(obj_list, 'value', seed=4)

Expand Down Expand Up @@ -116,6 +119,7 @@ def test_case_4(self):

def test_case_5(self):
# Input 5: Large list of objects
random.seed(5)
obj_list = [Object(value=random.gauss(0, 5)) for _ in range(1000)]
ax = f_1238(obj_list, 'value')

Expand Down
2 changes: 1 addition & 1 deletion data/clean/f_247_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def f_247(data, save_plot=False, plot_path=None):
Example:
>>> import tempfile
>>> temp_dir = tempfile.gettempdir()
>>> temp_dir = tempfile.mkdtemp()
>>> f_247([('A', 1, 1, 1), ('B', 2, 2, 2)], save_plot=True, plot_path=f"{temp_dir}/temp_plot.png")[0]
array([[ 8.66025404e-01, 4.09680598e-17],
[-8.66025404e-01, 4.09680598e-17]])
Expand Down
5 changes: 3 additions & 2 deletions data/clean/f_2695_junda_james.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ class TestCases(unittest.TestCase):
def setUp(self):
# Create a dummy image for testing
np.random.seed(42)
self.dummy_img_path = os.path.join(tempfile.gettempdir(), 'test_image.jpg')
self.dummy_img_path = os.path.join(tempfile.mkdtemp(), 'test_image.jpg')
dummy_img = np.random.randint(0, 255, (20, 20, 3), dtype=np.uint8)
cv2.imwrite(self.dummy_img_path, dummy_img)

def tearDown(self):
# Cleanup the dummy image
os.remove(self.dummy_img_path)
if os.path.exists(self.dummy_img_path):
os.remove(self.dummy_img_path)

def test_valid_input(self):
def dummy_onpick(event):
Expand Down
5 changes: 2 additions & 3 deletions data/clean/f_271_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ def setup_test_directory():
class TestCases(unittest.TestCase):
def setUp(self):
setup_test_directory()
super().setUp()

def tearDown(self):
shutil.rmtree(TEST_DIR_PATH)
super().tearDown()
if os.path.exists(TEST_DIR_PATH):
shutil.rmtree(TEST_DIR_PATH)

def test_case_1(self):
# Test with 5 JSON files containing various keys
Expand Down
14 changes: 7 additions & 7 deletions data/clean/f_2724_hanhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
def f_2726(X, y, n_splits, batch_size, epochs):
"""
Trains a simple neural network on provided data using k-fold cross-validation.
The network has one hidden layer with 50 neurons and ReLU activation, and
The network has one hidden layer with 20 neurons and ReLU activation, and
an output layer with sigmoid activation for binary classification.
Parameters:
X (numpy.array): The input data.
y (numpy.array): The target data.
n_splits (int): The number of splits for k-fold cross-validation. Default is 5.
batch_size (int): The size of the batch used during training. Default is 32.
epochs (int): The number of epochs for training the model. Default is 10.
epochs (int): The number of epochs for training the model. Default is 1.
Returns:
list: A list containing the training history of the model for each fold. Each history
Expand Down Expand Up @@ -47,7 +47,7 @@ def f_2726(X, y, n_splits, batch_size, epochs):
y_train, y_test = y[train_index], y[test_index]

model = tf.keras.models.Sequential([
tf.keras.layers.Dense(50, activation='relu'),
tf.keras.layers.Dense(20, activation='relu'),
tf.keras.layers.Dense(1, activation='sigmoid')
])

Expand All @@ -70,7 +70,7 @@ def setUp(self):
self.y = np.random.randint(0, 2, 100)
self.n_splits = 5
self.batch_size = 32
self.epochs = 10
self.epochs = 1

def test_return_type(self):
"""Test that the function returns a list."""
Expand Down Expand Up @@ -101,9 +101,9 @@ def test_effect_of_different_batch_sizes(self):

def test_effect_of_different_epochs(self):
"""Test function behavior with different epochs."""
for epochs in [5, 20]:
result = f_2726(self.X, self.y, self.n_splits, self.batch_size, epochs)
self.assertEqual(len(result), self.n_splits) # Validating function execution
epochs=5
result = f_2726(self.X, self.y, self.n_splits, self.batch_size, epochs)
self.assertEqual(len(result), self.n_splits) # Validating function execution


def run_tests():
Expand Down
9 changes: 4 additions & 5 deletions data/clean/f_288_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ def setUp(self) -> None:
self.temp_dir = f"{self.base_tmp_dir}/test"
if not os.path.exists(self.temp_dir):
os.mkdir(self.temp_dir)
return super().setUp()


def tearDown(self) -> None:
shutil.rmtree(self.base_tmp_dir)
return super().tearDown()
if os.path.exists(self.base_tmp_dir):
shutil.rmtree(self.base_tmp_dir)

def test_case_1(self):
# Test with the first sample directory
input_text = {
Expand Down
4 changes: 2 additions & 2 deletions data/clean/f_289_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def f_289(file_path, regex_pattern=r'\(.+?\)|\w+|[\W_]+'):
Example:
>>> import tempfile
>>> temp_dir = tempfile.gettempdir()
>>> temp_dir = tempfile.mkdtemp()
>>> file_path = os.path.join(temp_dir, 'data.csv')
>>> with open(file_path, 'w', newline='') as file:
... writer = csv.writer(file)
Expand Down Expand Up @@ -52,7 +52,7 @@ def f_289(file_path, regex_pattern=r'\(.+?\)|\w+|[\W_]+'):


class TestCases(unittest.TestCase):
base_tmp_dir = tempfile.gettempdir()
base_tmp_dir = tempfile.mkdtemp()
test_data_dir = f"{base_tmp_dir}/test"

def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion data/clean/f_290_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def f_290(file_path: str, regex_pattern=r'\(.+?\)|\w') -> dict:
Example:
>>> import tempfile
>>> temp_dir = tempfile.gettempdir()
>>> temp_dir = tempfile.mkdtemp()
>>> file_path = os.path.join(temp_dir, 'sample_data.json')
>>> with open(file_path, 'w') as file:
... json.dump({'content': 'This is a (sample) text with some (matches) and characters.'}, file)
Expand Down
10 changes: 4 additions & 6 deletions data/clean/f_294_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TestCases(unittest.TestCase):

def setUp(self):
self.extensions = ['*.txt', '*.md', '*.csv']
self.base_tmp_dir = tempfile.gettempdir()
self.base_tmp_dir = tempfile.mkdtemp()
self.test_directory = f"{self.base_tmp_dir}/test/"
os.makedirs(self.test_directory, exist_ok=True)

Expand All @@ -70,17 +70,15 @@ def setUp(self):
# Write the sample data to files
for filename, content in sample_files_data.items():
with (
open(os.path.join(self.test_directory, filename), 'w')
if os.path.exists(os.path.join(self.test_directory, filename))
else open(os.path.join(self.test_directory, filename), 'x')
open(os.path.join(self.test_directory, filename), 'w')
if os.path.exists(os.path.join(self.test_directory, filename))
else open(os.path.join(self.test_directory, filename), 'x')
) as file:
file.write(content)
return super().setUp()

def tearDown(self):
if os.path.exists(self.test_directory):
shutil.rmtree(self.test_directory)
return super().tearDown()

def test_case_1(self):
matched_files = f_294('.*hello.*', self.test_directory, self.extensions)
Expand Down
4 changes: 1 addition & 3 deletions data/clean/f_298_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ def setUp(self):
else open(path, "x")
) as file:
file.write(content)
super().setUp()

def tearDown(self):
shutil.rmtree(f"{self.base_dir}")
super().tearDown()


def test_case_1(self):
# Testing script1.py that should exit with code 0
return_code = f_298(self.script_paths[0])
Expand Down
9 changes: 4 additions & 5 deletions data/clean/f_300_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ def setUp(self):
file.write(content)
file_paths.append(file_path)

return super().setUp()


def tearDown(self):
# Reset the test folders after each test
shutil.rmtree(self.base_tmp_dir, ignore_errors=True)
return super().tearDown()
if os.path.exists(self.base_tmp_dir):
shutil.rmtree(self.base_tmp_dir, ignore_errors=True)

def test_case_1(self):
"""Test basic functionality."""
# Create some sample files in the source folder
Expand Down
1 change: 0 additions & 1 deletion data/clean/f_304_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class TestCases(unittest.TestCase):
def tearDown(self) -> None:
if os.path.exists(self.file_name):
os.remove(self.file_name)
return super().tearDown()

def test_case_1(self):
# Test with n = 3
Expand Down
5 changes: 2 additions & 3 deletions data/clean/f_306_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ def setUp(self):

for dir_name in self.dest_dirs.keys():
os.makedirs(dir_name, exist_ok=True)
return super().setUp()

def tearDown(self):
shutil.rmtree(self.base_test_dir)
return super().tearDown()
if os.path.exists(self.base_test_dir):
shutil.rmtree(self.base_test_dir)

def test_case_1(self):
moved_file = f_306(
Expand Down
5 changes: 2 additions & 3 deletions data/clean/f_307_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ def setUp(self):

with open(os.path.join(self.test_directory, "file2.json"), "w") as file:
json.dump(self.json_data2, file)
super(TestCases, self).setUp()

def tearDown(self):
shutil.rmtree(self.test_directory)
super(TestCases, self).tearDown()
if os.path.exists(self.test_directory):
shutil.rmtree(self.test_directory)

def test_case_1(self):
# Test with the sample directory created
Expand Down
6 changes: 2 additions & 4 deletions data/clean/f_308_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ def setUp(self):
doc.add_paragraph(paragraph)
doc.save(self.test_directory + file_name)

super(TestCases, self).setUp()

def tearDown(self):
shutil.rmtree(self.test_directory)
super(TestCases, self).tearDown()
if os.path.exists(self.test_directory):
shutil.rmtree(self.test_directory)

def read_docx_content(self, file_path):
doc = Document(file_path)
Expand Down
45 changes: 25 additions & 20 deletions data/clean/f_309_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def f_309(directory_path='./xlsx_files/'):
for row in workbook[sheet].iter_rows():
for cell in row:
if isinstance(cell.value, str):
cell.value = re.sub(r'(?<=(^|[^\\])(\\\\)*)"', r'\"', cell.value)
cell.value = re.sub(r'(?<=(^|[^\\])(\\\\)*)"', r'\"',
cell.value)

workbook.save(xlsx_file)
processed_files += 1
Expand Down Expand Up @@ -104,54 +105,58 @@ def setUp(self):
sheet = workbook.create_sheet(title=sheet_name)
for row in rows:
sheet.append(row)
workbook.save(filename=os.path.join(self.test_directory, file_info["filename"]))

super(TestCases, self).setUp()
workbook.save(
filename=os.path.join(self.test_directory, file_info["filename"]))

def tearDown(self):
# Remove the test directory
shutil.rmtree(self.test_directory)
super(TestCases, self).tearDown()

if os.path.exists(self.test_directory):
shutil.rmtree(self.test_directory)

def test_case_1(self):
# Process the mock Excel files
processed_files_count = f_309(directory_path=self.test_directory)

# Check the number of processed files
self.assertEqual(processed_files_count, 3)

# Check the content of file1.xlsx
workbook = load_workbook(filename=os.path.join(self.test_directory, "file1.xlsx"))
workbook = load_workbook(
filename=os.path.join(self.test_directory, "file1.xlsx"))
sheet = workbook.active
self.assertEqual(sheet.cell(row=1, column=3).value, 'This is a \\"test\\" string.')
self.assertEqual(sheet.cell(row=1, column=3).value,
'This is a \\"test\\" string.')
self.assertEqual(sheet.cell(row=2, column=2).value, 'Row with \\"quotes\\"')
self.assertEqual(sheet.cell(row=2, column=3).value, 'And \\"more\\" quotes.')

def test_case_2(self):
# Check the content of file2.xlsx
workbook = load_workbook(filename=os.path.join(self.test_directory, "file2.xlsx"))
workbook = load_workbook(
filename=os.path.join(self.test_directory, "file2.xlsx"))
sheet1 = workbook["Sheet1"]
self.assertEqual(sheet1.cell(row=1, column=1).value, 'Just a')

sheet2 = workbook["Sheet2"]
self.assertEqual(sheet2.cell(row=1, column=2).value, "Another \"quoted\" string.")

self.assertEqual(sheet2.cell(row=1, column=2).value,
"Another \"quoted\" string.")

def test_case_3(self):
# Check the content of file3.xlsx
workbook = load_workbook(filename=os.path.join(self.test_directory, "file3.xlsx"))
workbook = load_workbook(
filename=os.path.join(self.test_directory, "file3.xlsx"))
sheet = workbook.active
self.assertEqual(sheet.cell(row=1, column=1).value, 'A simple')

def test_case_4(self):
# Test with a directory that doesn't exist
with self.assertRaises(FileNotFoundError):
f_309(directory_path="/invalid/directory/")

def test_case_5(self):
# Test with a directory that contains no .xlsx files
os.makedirs(f"{self.test_directory}/empty_directory/", exist_ok=True)
processed_files_count = f_309(directory_path=f"{self.test_directory}/empty_directory/")
processed_files_count = f_309(
directory_path=f"{self.test_directory}/empty_directory/")
self.assertEqual(processed_files_count, 0)


Expand Down
1 change: 0 additions & 1 deletion data/clean/f_312_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def f_312(text, n, top_k):
class TestCases(unittest.TestCase):
def tearDown(self) -> None:
plt.close('all')
return super().tearDown()

def test_case_1(self):
# Test with a simple text, bigram (n=2) and top 2 n-grams
Expand Down
Loading

0 comments on commit 3634448

Please sign in to comment.