Skip to content

Commit 3634448

Browse files
committed
update: add data pack
1 parent 738fdbd commit 3634448

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1328
-1272
lines changed

data/clean/f_243_indraneil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class TestCases(unittest.TestCase):
5757

5858
def setUp(self):
5959
# Set up the test file path
60-
self.temp_dir = tempfile.gettempdir()
60+
self.temp_dir = tempfile.mkdtemp()
6161
self.test_file_path = f"{self.temp_dir}/test_log.json"
6262

6363
def tearDown(self):

data/clean/f_245_indraneil.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def f_1238(obj_list, attr, num_bins=30, seed=0):
6161
class TestCases(unittest.TestCase):
6262
def test_case_1(self):
6363
# Input 1: Simple list of objects with integer values from 0 to 9
64+
random.seed(1)
6465
obj_list = [Object(value=i) for i in range(10)]
6566
ax = f_1238(obj_list, 'value')
6667

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

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

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

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

@@ -116,6 +119,7 @@ def test_case_4(self):
116119

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

data/clean/f_247_indraneil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def f_247(data, save_plot=False, plot_path=None):
2828
2929
Example:
3030
>>> import tempfile
31-
>>> temp_dir = tempfile.gettempdir()
31+
>>> temp_dir = tempfile.mkdtemp()
3232
>>> f_247([('A', 1, 1, 1), ('B', 2, 2, 2)], save_plot=True, plot_path=f"{temp_dir}/temp_plot.png")[0]
3333
array([[ 8.66025404e-01, 4.09680598e-17],
3434
[-8.66025404e-01, 4.09680598e-17]])

data/clean/f_2695_junda_james.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ class TestCases(unittest.TestCase):
6666
def setUp(self):
6767
# Create a dummy image for testing
6868
np.random.seed(42)
69-
self.dummy_img_path = os.path.join(tempfile.gettempdir(), 'test_image.jpg')
69+
self.dummy_img_path = os.path.join(tempfile.mkdtemp(), 'test_image.jpg')
7070
dummy_img = np.random.randint(0, 255, (20, 20, 3), dtype=np.uint8)
7171
cv2.imwrite(self.dummy_img_path, dummy_img)
7272

7373
def tearDown(self):
7474
# Cleanup the dummy image
75-
os.remove(self.dummy_img_path)
75+
if os.path.exists(self.dummy_img_path):
76+
os.remove(self.dummy_img_path)
7677

7778
def test_valid_input(self):
7879
def dummy_onpick(event):

data/clean/f_271_indraneil.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@ def setup_test_directory():
7676
class TestCases(unittest.TestCase):
7777
def setUp(self):
7878
setup_test_directory()
79-
super().setUp()
8079

8180
def tearDown(self):
82-
shutil.rmtree(TEST_DIR_PATH)
83-
super().tearDown()
81+
if os.path.exists(TEST_DIR_PATH):
82+
shutil.rmtree(TEST_DIR_PATH)
8483

8584
def test_case_1(self):
8685
# Test with 5 JSON files containing various keys

data/clean/f_2724_hanhu.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
def f_2726(X, y, n_splits, batch_size, epochs):
66
"""
77
Trains a simple neural network on provided data using k-fold cross-validation.
8-
The network has one hidden layer with 50 neurons and ReLU activation, and
8+
The network has one hidden layer with 20 neurons and ReLU activation, and
99
an output layer with sigmoid activation for binary classification.
1010
1111
Parameters:
1212
X (numpy.array): The input data.
1313
y (numpy.array): The target data.
1414
n_splits (int): The number of splits for k-fold cross-validation. Default is 5.
1515
batch_size (int): The size of the batch used during training. Default is 32.
16-
epochs (int): The number of epochs for training the model. Default is 10.
16+
epochs (int): The number of epochs for training the model. Default is 1.
1717
1818
Returns:
1919
list: A list containing the training history of the model for each fold. Each history
@@ -47,7 +47,7 @@ def f_2726(X, y, n_splits, batch_size, epochs):
4747
y_train, y_test = y[train_index], y[test_index]
4848

4949
model = tf.keras.models.Sequential([
50-
tf.keras.layers.Dense(50, activation='relu'),
50+
tf.keras.layers.Dense(20, activation='relu'),
5151
tf.keras.layers.Dense(1, activation='sigmoid')
5252
])
5353

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

7575
def test_return_type(self):
7676
"""Test that the function returns a list."""
@@ -101,9 +101,9 @@ def test_effect_of_different_batch_sizes(self):
101101

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

108108

109109
def run_tests():

data/clean/f_288_indraneil.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ def setUp(self) -> None:
5252
self.temp_dir = f"{self.base_tmp_dir}/test"
5353
if not os.path.exists(self.temp_dir):
5454
os.mkdir(self.temp_dir)
55-
return super().setUp()
56-
55+
5756
def tearDown(self) -> None:
58-
shutil.rmtree(self.base_tmp_dir)
59-
return super().tearDown()
60-
57+
if os.path.exists(self.base_tmp_dir):
58+
shutil.rmtree(self.base_tmp_dir)
59+
6160
def test_case_1(self):
6261
# Test with the first sample directory
6362
input_text = {

data/clean/f_289_indraneil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def f_289(file_path, regex_pattern=r'\(.+?\)|\w+|[\W_]+'):
2323
2424
Example:
2525
>>> import tempfile
26-
>>> temp_dir = tempfile.gettempdir()
26+
>>> temp_dir = tempfile.mkdtemp()
2727
>>> file_path = os.path.join(temp_dir, 'data.csv')
2828
>>> with open(file_path, 'w', newline='') as file:
2929
... writer = csv.writer(file)
@@ -52,7 +52,7 @@ def f_289(file_path, regex_pattern=r'\(.+?\)|\w+|[\W_]+'):
5252

5353

5454
class TestCases(unittest.TestCase):
55-
base_tmp_dir = tempfile.gettempdir()
55+
base_tmp_dir = tempfile.mkdtemp()
5656
test_data_dir = f"{base_tmp_dir}/test"
5757

5858
def setUp(self):

data/clean/f_290_indraneil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def f_290(file_path: str, regex_pattern=r'\(.+?\)|\w') -> dict:
2222
2323
Example:
2424
>>> import tempfile
25-
>>> temp_dir = tempfile.gettempdir()
25+
>>> temp_dir = tempfile.mkdtemp()
2626
>>> file_path = os.path.join(temp_dir, 'sample_data.json')
2727
>>> with open(file_path, 'w') as file:
2828
... json.dump({'content': 'This is a (sample) text with some (matches) and characters.'}, file)

data/clean/f_294_indraneil.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class TestCases(unittest.TestCase):
5454

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

@@ -70,17 +70,15 @@ def setUp(self):
7070
# Write the sample data to files
7171
for filename, content in sample_files_data.items():
7272
with (
73-
open(os.path.join(self.test_directory, filename), 'w')
74-
if os.path.exists(os.path.join(self.test_directory, filename))
75-
else open(os.path.join(self.test_directory, filename), 'x')
73+
open(os.path.join(self.test_directory, filename), 'w')
74+
if os.path.exists(os.path.join(self.test_directory, filename))
75+
else open(os.path.join(self.test_directory, filename), 'x')
7676
) as file:
7777
file.write(content)
78-
return super().setUp()
7978

8079
def tearDown(self):
8180
if os.path.exists(self.test_directory):
8281
shutil.rmtree(self.test_directory)
83-
return super().tearDown()
8482

8583
def test_case_1(self):
8684
matched_files = f_294('.*hello.*', self.test_directory, self.extensions)

0 commit comments

Comments
 (0)