Skip to content

Commit 2c8136a

Browse files
committed
fix: PCA test cases
1 parent bcd05d0 commit 2c8136a

20 files changed

+1206
-1145
lines changed

data/clean/f_1727_junda_james.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ def test_values(self):
8383

8484
# Assert each pair of tuples is approximately equal
8585
for actual, expected in zip(df_tuples, expect_tuples):
86-
self.assertAlmostEqual(actual[0], expected[0], places=7, msg="DataFrame contents should match the expected output")
87-
self.assertAlmostEqual(actual[1], expected[1], places=7, msg="DataFrame contents should match the expected output")
86+
try:
87+
self.assertAlmostEqual(actual[0], expected[0], places=7, msg="DataFrame contents should match the expected output")
88+
self.assertAlmostEqual(actual[1], expected[1], places=7, msg="DataFrame contents should match the expected output")
89+
except:
90+
self.assertAlmostEqual(actual[0], -expected[0], places=7, msg="DataFrame contents should match the expected output")
91+
self.assertAlmostEqual(actual[1], -expected[1], places=7, msg="DataFrame contents should match the expected output")
8892

8993
def run_tests():
9094
"""Run all tests for this function."""

data/clean/f_1776_junda_james.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ def test_return_types(self):
7070
for a, b in zip(df_list, expect):
7171
a1, a2 = str(a).split(',')
7272
b1, b2 = str(b).split(',')
73-
self.assertAlmostEqual(float(a1), float(b1), places=7)
74-
self.assertAlmostEqual(float(a2), float(b2), places=7)
75-
# self.assertEqual(df_list, expect, "DataFrame contents should match the expected output")
73+
try:
74+
self.assertAlmostEqual(float(a1), float(b1), places=7)
75+
self.assertAlmostEqual(float(a2), float(b2), places=7)
76+
except:
77+
self.assertAlmostEqual(float(a1), -float(b1), places=7)
78+
self.assertAlmostEqual(float(a2), -float(b2), places=7)
7679

7780
def test_invalid_input_empty_dataframe(self):
7881
with self.assertRaises(ValueError):

data/clean/f_247_indraneil.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,17 @@ def test_case_5(self):
9898
self.assertIsInstance(result, np.ndarray)
9999
self.assertEqual(result.shape, (10, 2))
100100
# Test the return value
101+
# Expected result (can have flipped signs)
102+
expected = np.array([
103+
[-7.79, 0.], [-6.06, 0.], [-4.33, 0.], [-2.6, 0.], [-0.87, 0.],
104+
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, 0.], [7.79, 0.]
105+
])
106+
107+
# Check if either the original or the sign-flipped version matches
108+
flipped = -expected
101109
self.assertTrue(
102-
np.allclose(
103-
result,
104-
[
105-
[-7.79, 0.], [-6.06, 0.], [-4.33, -0.], [-2.6, -0.], [-0.87, -0.],
106-
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, -0.], [7.79, 0.]
107-
],
108-
atol=0.1
109-
)
110+
np.allclose(result, expected, atol=0.1) or np.allclose(result, flipped, atol=0.1),
111+
"The PCA results do not match the expected values considering possible sign flips."
110112
)
111113

112114

data/clean/f_405_jenny.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,19 @@ def test_case_8(self):
112112
data = [[2, 3], [3, 4], [5, 6]]
113113
_, transformed_data = f_405(data)
114114
# Using the sklearn PCA output as the expected transformation
115-
expected_transformation = np.array(
115+
expected = np.array(
116116
[
117117
[-1.88561808e00, 1.93816421e-16],
118118
[-4.71404521e-01, 3.32511118e-16],
119119
[2.35702260e00, 2.21555360e-16],
120120
]
121121
)
122-
np.testing.assert_almost_equal(
123-
transformed_data, expected_transformation, decimal=5
122+
123+
# Check if either the original or the sign-flipped version matches
124+
flipped = -expected
125+
self.assertTrue(
126+
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
127+
"The PCA results do not match the expected values considering possible sign flips."
124128
)
125129

126130
def test_case_9(self):

data/clean/f_565_niklas.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ def test_case_4(self):
5858
def test_case_5(self):
5959
transformed_data = f_565([(-1, -1, -1), (0, 0, 0), (1, 1, 1)], 1)
6060
self.assertEqual(transformed_data.shape, (3, 1))
61-
self.assertTrue(transformed_data[0][0] < 0)
6261
self.assertTrue(transformed_data[1][0] == 0)
63-
self.assertTrue(transformed_data[2][0] > 0)
62+
try:
63+
self.assertTrue(transformed_data[0][0] < 0)
64+
self.assertTrue(transformed_data[2][0] > 0)
65+
except:
66+
self.assertTrue(transformed_data[0][0] > 0)
67+
self.assertTrue(transformed_data[2][0] < 0)
6468

6569
run_tests()
6670
if __name__ == "__main__":

data/clean/f_719_simon.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,19 @@ def test_empty_dataframe(self):
116116
f_719(data_empty)
117117

118118
def test_known_input(self):
119-
expected_output = np.array([
119+
expected = np.array([
120120
[ 2.82842712e+00, 3.64856517e-16],
121121
[ 1.41421356e+00, -1.21618839e-16],
122122
[-0.00000000e+00, 0.00000000e+00],
123123
[-1.41421356e+00, 1.21618839e-16],
124124
[-2.82842712e+00, 2.43237678e-16]
125125
])
126-
actual_output = f_719(self.data_small, n_components=2).values
127-
np.testing.assert_almost_equal(actual_output, expected_output, decimal=5)
128-
126+
flipped = -expected
127+
transformed_data = f_719(self.data_small, n_components=2).values
128+
self.assertTrue(
129+
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
130+
"The PCA results do not match the expected values considering possible sign flips."
131+
)
129132

130133
def run_tests():
131134
suite = unittest.TestSuite()

data/processed/136_w_doc.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ def test_return_types(self):
6363
for a, b in zip(df_list, expect):
6464
a1, a2 = str(a).split(',')
6565
b1, b2 = str(b).split(',')
66-
self.assertAlmostEqual(float(a1), float(b1), places=7)
67-
self.assertAlmostEqual(float(a2), float(b2), places=7)
68-
# self.assertEqual(df_list, expect, "DataFrame contents should match the expected output")
66+
try:
67+
self.assertAlmostEqual(float(a1), float(b1), places=7)
68+
self.assertAlmostEqual(float(a2), float(b2), places=7)
69+
except:
70+
self.assertAlmostEqual(float(a1), -float(b1), places=7)
71+
self.assertAlmostEqual(float(a2), -float(b2), places=7)
6972
def test_invalid_input_empty_dataframe(self):
7073
with self.assertRaises(ValueError):
7174
task_func(pd.DataFrame())

data/processed/237_wo_doc.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ def test_case_5(self):
8787
self.assertIsInstance(result, np.ndarray)
8888
self.assertEqual(result.shape, (10, 2))
8989
# Test the return value
90+
# Expected result (can have flipped signs)
91+
expected = np.array([
92+
[-7.79, 0.], [-6.06, 0.], [-4.33, 0.], [-2.6, 0.], [-0.87, 0.],
93+
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, 0.], [7.79, 0.]
94+
])
95+
96+
# Check if either the original or the sign-flipped version matches
97+
flipped = -expected
9098
self.assertTrue(
91-
np.allclose(
92-
result,
93-
[
94-
[-7.79, 0.], [-6.06, 0.], [-4.33, -0.], [-2.6, -0.], [-0.87, -0.],
95-
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, -0.], [7.79, 0.]
96-
],
97-
atol=0.1
98-
)
99+
np.allclose(result, expected, atol=0.1) or np.allclose(result, flipped, atol=0.1),
100+
"The PCA results do not match the expected values considering possible sign flips."
99101
)

data/processed/517_w_doc.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,19 @@ def test_case_8(self):
100100
data = [[2, 3], [3, 4], [5, 6]]
101101
_, transformed_data = task_func(data)
102102
# Using the sklearn PCA output as the expected transformation
103-
expected_transformation = np.array(
103+
expected = np.array(
104104
[
105105
[-1.88561808e00, 1.93816421e-16],
106106
[-4.71404521e-01, 3.32511118e-16],
107107
[2.35702260e00, 2.21555360e-16],
108108
]
109109
)
110-
np.testing.assert_almost_equal(
111-
transformed_data, expected_transformation, decimal=5
110+
111+
# Check if either the original or the sign-flipped version matches
112+
flipped = -expected
113+
self.assertTrue(
114+
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
115+
"The PCA results do not match the expected values considering possible sign flips."
112116
)
113117
def test_case_9(self):
114118
# Test floats

data/processed/695_w_doc.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def test_case_4(self):
4646
def test_case_5(self):
4747
transformed_data = task_func([(-1, -1, -1), (0, 0, 0), (1, 1, 1)], 1)
4848
self.assertEqual(transformed_data.shape, (3, 1))
49-
self.assertTrue(transformed_data[0][0] < 0)
5049
self.assertTrue(transformed_data[1][0] == 0)
51-
self.assertTrue(transformed_data[2][0] > 0)
50+
try:
51+
self.assertTrue(transformed_data[0][0] < 0)
52+
self.assertTrue(transformed_data[2][0] > 0)
53+
except:
54+
self.assertTrue(transformed_data[0][0] > 0)
55+
self.assertTrue(transformed_data[2][0] < 0)

data/processed/877_w_doc.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,16 @@ def test_empty_dataframe(self):
106106
with self.assertRaises(ValueError):
107107
task_func(data_empty)
108108
def test_known_input(self):
109-
expected_output = np.array([
109+
expected = np.array([
110110
[ 2.82842712e+00, 3.64856517e-16],
111111
[ 1.41421356e+00, -1.21618839e-16],
112112
[-0.00000000e+00, 0.00000000e+00],
113113
[-1.41421356e+00, 1.21618839e-16],
114114
[-2.82842712e+00, 2.43237678e-16]
115115
])
116-
actual_output = task_func(self.data_small, n_components=2).values
117-
np.testing.assert_almost_equal(actual_output, expected_output, decimal=5)
116+
flipped = -expected
117+
transformed_data = task_func(self.data_small, n_components=2).values
118+
self.assertTrue(
119+
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
120+
"The PCA results do not match the expected values considering possible sign flips."
121+
)

data/processed/93_w_doc.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,9 @@ def test_values(self):
7272
expect_tuples = [tuple(map(float, item.split(','))) for item in expect]
7373
# Assert each pair of tuples is approximately equal
7474
for actual, expected in zip(df_tuples, expect_tuples):
75-
self.assertAlmostEqual(actual[0], expected[0], places=7, msg="DataFrame contents should match the expected output")
76-
self.assertAlmostEqual(actual[1], expected[1], places=7, msg="DataFrame contents should match the expected output")
75+
try:
76+
self.assertAlmostEqual(actual[0], expected[0], places=7, msg="DataFrame contents should match the expected output")
77+
self.assertAlmostEqual(actual[1], expected[1], places=7, msg="DataFrame contents should match the expected output")
78+
except:
79+
self.assertAlmostEqual(actual[0], -expected[0], places=7, msg="DataFrame contents should match the expected output")
80+
self.assertAlmostEqual(actual[1], -expected[1], places=7, msg="DataFrame contents should match the expected output")

data/raw/f_1727_junda_james.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ def test_values(self):
8383

8484
# Assert each pair of tuples is approximately equal
8585
for actual, expected in zip(df_tuples, expect_tuples):
86-
self.assertAlmostEqual(actual[0], expected[0], places=7, msg="DataFrame contents should match the expected output")
87-
self.assertAlmostEqual(actual[1], expected[1], places=7, msg="DataFrame contents should match the expected output")
86+
try:
87+
self.assertAlmostEqual(actual[0], expected[0], places=7, msg="DataFrame contents should match the expected output")
88+
self.assertAlmostEqual(actual[1], expected[1], places=7, msg="DataFrame contents should match the expected output")
89+
except:
90+
self.assertAlmostEqual(actual[0], -expected[0], places=7, msg="DataFrame contents should match the expected output")
91+
self.assertAlmostEqual(actual[1], -expected[1], places=7, msg="DataFrame contents should match the expected output")
8892

8993
def run_tests():
9094
"""Run all tests for this function."""

data/raw/f_1776_junda_james.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ def test_return_types(self):
7070
for a, b in zip(df_list, expect):
7171
a1, a2 = str(a).split(',')
7272
b1, b2 = str(b).split(',')
73-
self.assertAlmostEqual(float(a1), float(b1), places=7)
74-
self.assertAlmostEqual(float(a2), float(b2), places=7)
75-
# self.assertEqual(df_list, expect, "DataFrame contents should match the expected output")
73+
try:
74+
self.assertAlmostEqual(float(a1), float(b1), places=7)
75+
self.assertAlmostEqual(float(a2), float(b2), places=7)
76+
except:
77+
self.assertAlmostEqual(float(a1), -float(b1), places=7)
78+
self.assertAlmostEqual(float(a2), -float(b2), places=7)
7679

7780
def test_invalid_input_empty_dataframe(self):
7881
with self.assertRaises(ValueError):

data/raw/f_247_indraneil.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,17 @@ def test_case_5(self):
9898
self.assertIsInstance(result, np.ndarray)
9999
self.assertEqual(result.shape, (10, 2))
100100
# Test the return value
101+
# Expected result (can have flipped signs)
102+
expected = np.array([
103+
[-7.79, 0.], [-6.06, 0.], [-4.33, 0.], [-2.6, 0.], [-0.87, 0.],
104+
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, 0.], [7.79, 0.]
105+
])
106+
107+
# Check if either the original or the sign-flipped version matches
108+
flipped = -expected
101109
self.assertTrue(
102-
np.allclose(
103-
result,
104-
[
105-
[-7.79, 0.], [-6.06, 0.], [-4.33, -0.], [-2.6, -0.], [-0.87, -0.],
106-
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, -0.], [7.79, 0.]
107-
],
108-
atol=0.1
109-
)
110+
np.allclose(result, expected, atol=0.1) or np.allclose(result, flipped, atol=0.1),
111+
"The PCA results do not match the expected values considering possible sign flips."
110112
)
111113

112114

data/raw/f_405_jenny.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,19 @@ def test_case_8(self):
112112
data = [[2, 3], [3, 4], [5, 6]]
113113
_, transformed_data = f_405(data)
114114
# Using the sklearn PCA output as the expected transformation
115-
expected_transformation = np.array(
115+
expected = np.array(
116116
[
117117
[-1.88561808e00, 1.93816421e-16],
118118
[-4.71404521e-01, 3.32511118e-16],
119119
[2.35702260e00, 2.21555360e-16],
120120
]
121121
)
122-
np.testing.assert_almost_equal(
123-
transformed_data, expected_transformation, decimal=5
122+
123+
# Check if either the original or the sign-flipped version matches
124+
flipped = -expected
125+
self.assertTrue(
126+
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
127+
"The PCA results do not match the expected values considering possible sign flips."
124128
)
125129

126130
def test_case_9(self):

data/raw/f_565_niklas.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ def test_case_4(self):
5858
def test_case_5(self):
5959
transformed_data = f_565([(-1, -1, -1), (0, 0, 0), (1, 1, 1)], 1)
6060
self.assertEqual(transformed_data.shape, (3, 1))
61-
self.assertTrue(transformed_data[0][0] < 0)
6261
self.assertTrue(transformed_data[1][0] == 0)
63-
self.assertTrue(transformed_data[2][0] > 0)
62+
try:
63+
self.assertTrue(transformed_data[0][0] < 0)
64+
self.assertTrue(transformed_data[2][0] > 0)
65+
except:
66+
self.assertTrue(transformed_data[0][0] > 0)
67+
self.assertTrue(transformed_data[2][0] < 0)
6468

6569
run_tests()
6670
if __name__ == "__main__":

data/raw/f_719_simon.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,19 @@ def test_empty_dataframe(self):
116116
f_719(data_empty)
117117

118118
def test_known_input(self):
119-
expected_output = np.array([
119+
expected = np.array([
120120
[ 2.82842712e+00, 3.64856517e-16],
121121
[ 1.41421356e+00, -1.21618839e-16],
122122
[-0.00000000e+00, 0.00000000e+00],
123123
[-1.41421356e+00, 1.21618839e-16],
124124
[-2.82842712e+00, 2.43237678e-16]
125125
])
126-
actual_output = f_719(self.data_small, n_components=2).values
127-
np.testing.assert_almost_equal(actual_output, expected_output, decimal=5)
128-
126+
flipped = -expected
127+
transformed_data = f_719(self.data_small, n_components=2).values
128+
self.assertTrue(
129+
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
130+
"The PCA results do not match the expected values considering possible sign flips."
131+
)
129132

130133
def run_tests():
131134
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)