Skip to content

Commit

Permalink
fix: PCA test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
terryyz committed May 14, 2024
1 parent bcd05d0 commit 2c8136a
Show file tree
Hide file tree
Showing 20 changed files with 1,206 additions and 1,145 deletions.
8 changes: 6 additions & 2 deletions data/clean/f_1727_junda_james.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ def test_values(self):

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

def run_tests():
"""Run all tests for this function."""
Expand Down
9 changes: 6 additions & 3 deletions data/clean/f_1776_junda_james.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ def test_return_types(self):
for a, b in zip(df_list, expect):
a1, a2 = str(a).split(',')
b1, b2 = str(b).split(',')
self.assertAlmostEqual(float(a1), float(b1), places=7)
self.assertAlmostEqual(float(a2), float(b2), places=7)
# self.assertEqual(df_list, expect, "DataFrame contents should match the expected output")
try:
self.assertAlmostEqual(float(a1), float(b1), places=7)
self.assertAlmostEqual(float(a2), float(b2), places=7)
except:
self.assertAlmostEqual(float(a1), -float(b1), places=7)
self.assertAlmostEqual(float(a2), -float(b2), places=7)

def test_invalid_input_empty_dataframe(self):
with self.assertRaises(ValueError):
Expand Down
18 changes: 10 additions & 8 deletions data/clean/f_247_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ def test_case_5(self):
self.assertIsInstance(result, np.ndarray)
self.assertEqual(result.shape, (10, 2))
# Test the return value
# Expected result (can have flipped signs)
expected = np.array([
[-7.79, 0.], [-6.06, 0.], [-4.33, 0.], [-2.6, 0.], [-0.87, 0.],
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, 0.], [7.79, 0.]
])

# Check if either the original or the sign-flipped version matches
flipped = -expected
self.assertTrue(
np.allclose(
result,
[
[-7.79, 0.], [-6.06, 0.], [-4.33, -0.], [-2.6, -0.], [-0.87, -0.],
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, -0.], [7.79, 0.]
],
atol=0.1
)
np.allclose(result, expected, atol=0.1) or np.allclose(result, flipped, atol=0.1),
"The PCA results do not match the expected values considering possible sign flips."
)


Expand Down
10 changes: 7 additions & 3 deletions data/clean/f_405_jenny.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,19 @@ def test_case_8(self):
data = [[2, 3], [3, 4], [5, 6]]
_, transformed_data = f_405(data)
# Using the sklearn PCA output as the expected transformation
expected_transformation = np.array(
expected = np.array(
[
[-1.88561808e00, 1.93816421e-16],
[-4.71404521e-01, 3.32511118e-16],
[2.35702260e00, 2.21555360e-16],
]
)
np.testing.assert_almost_equal(
transformed_data, expected_transformation, decimal=5

# Check if either the original or the sign-flipped version matches
flipped = -expected
self.assertTrue(
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
"The PCA results do not match the expected values considering possible sign flips."
)

def test_case_9(self):
Expand Down
8 changes: 6 additions & 2 deletions data/clean/f_565_niklas.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ def test_case_4(self):
def test_case_5(self):
transformed_data = f_565([(-1, -1, -1), (0, 0, 0), (1, 1, 1)], 1)
self.assertEqual(transformed_data.shape, (3, 1))
self.assertTrue(transformed_data[0][0] < 0)
self.assertTrue(transformed_data[1][0] == 0)
self.assertTrue(transformed_data[2][0] > 0)
try:
self.assertTrue(transformed_data[0][0] < 0)
self.assertTrue(transformed_data[2][0] > 0)
except:
self.assertTrue(transformed_data[0][0] > 0)
self.assertTrue(transformed_data[2][0] < 0)

run_tests()
if __name__ == "__main__":
Expand Down
11 changes: 7 additions & 4 deletions data/clean/f_719_simon.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,19 @@ def test_empty_dataframe(self):
f_719(data_empty)

def test_known_input(self):
expected_output = np.array([
expected = np.array([
[ 2.82842712e+00, 3.64856517e-16],
[ 1.41421356e+00, -1.21618839e-16],
[-0.00000000e+00, 0.00000000e+00],
[-1.41421356e+00, 1.21618839e-16],
[-2.82842712e+00, 2.43237678e-16]
])
actual_output = f_719(self.data_small, n_components=2).values
np.testing.assert_almost_equal(actual_output, expected_output, decimal=5)

flipped = -expected
transformed_data = f_719(self.data_small, n_components=2).values
self.assertTrue(
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
"The PCA results do not match the expected values considering possible sign flips."
)

def run_tests():
suite = unittest.TestSuite()
Expand Down
9 changes: 6 additions & 3 deletions data/processed/136_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ def test_return_types(self):
for a, b in zip(df_list, expect):
a1, a2 = str(a).split(',')
b1, b2 = str(b).split(',')
self.assertAlmostEqual(float(a1), float(b1), places=7)
self.assertAlmostEqual(float(a2), float(b2), places=7)
# self.assertEqual(df_list, expect, "DataFrame contents should match the expected output")
try:
self.assertAlmostEqual(float(a1), float(b1), places=7)
self.assertAlmostEqual(float(a2), float(b2), places=7)
except:
self.assertAlmostEqual(float(a1), -float(b1), places=7)
self.assertAlmostEqual(float(a2), -float(b2), places=7)
def test_invalid_input_empty_dataframe(self):
with self.assertRaises(ValueError):
task_func(pd.DataFrame())
Expand Down
18 changes: 10 additions & 8 deletions data/processed/237_wo_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ def test_case_5(self):
self.assertIsInstance(result, np.ndarray)
self.assertEqual(result.shape, (10, 2))
# Test the return value
# Expected result (can have flipped signs)
expected = np.array([
[-7.79, 0.], [-6.06, 0.], [-4.33, 0.], [-2.6, 0.], [-0.87, 0.],
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, 0.], [7.79, 0.]
])

# Check if either the original or the sign-flipped version matches
flipped = -expected
self.assertTrue(
np.allclose(
result,
[
[-7.79, 0.], [-6.06, 0.], [-4.33, -0.], [-2.6, -0.], [-0.87, -0.],
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, -0.], [7.79, 0.]
],
atol=0.1
)
np.allclose(result, expected, atol=0.1) or np.allclose(result, flipped, atol=0.1),
"The PCA results do not match the expected values considering possible sign flips."
)
10 changes: 7 additions & 3 deletions data/processed/517_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,19 @@ def test_case_8(self):
data = [[2, 3], [3, 4], [5, 6]]
_, transformed_data = task_func(data)
# Using the sklearn PCA output as the expected transformation
expected_transformation = np.array(
expected = np.array(
[
[-1.88561808e00, 1.93816421e-16],
[-4.71404521e-01, 3.32511118e-16],
[2.35702260e00, 2.21555360e-16],
]
)
np.testing.assert_almost_equal(
transformed_data, expected_transformation, decimal=5

# Check if either the original or the sign-flipped version matches
flipped = -expected
self.assertTrue(
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
"The PCA results do not match the expected values considering possible sign flips."
)
def test_case_9(self):
# Test floats
Expand Down
8 changes: 6 additions & 2 deletions data/processed/695_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def test_case_4(self):
def test_case_5(self):
transformed_data = task_func([(-1, -1, -1), (0, 0, 0), (1, 1, 1)], 1)
self.assertEqual(transformed_data.shape, (3, 1))
self.assertTrue(transformed_data[0][0] < 0)
self.assertTrue(transformed_data[1][0] == 0)
self.assertTrue(transformed_data[2][0] > 0)
try:
self.assertTrue(transformed_data[0][0] < 0)
self.assertTrue(transformed_data[2][0] > 0)
except:
self.assertTrue(transformed_data[0][0] > 0)
self.assertTrue(transformed_data[2][0] < 0)
10 changes: 7 additions & 3 deletions data/processed/877_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ def test_empty_dataframe(self):
with self.assertRaises(ValueError):
task_func(data_empty)
def test_known_input(self):
expected_output = np.array([
expected = np.array([
[ 2.82842712e+00, 3.64856517e-16],
[ 1.41421356e+00, -1.21618839e-16],
[-0.00000000e+00, 0.00000000e+00],
[-1.41421356e+00, 1.21618839e-16],
[-2.82842712e+00, 2.43237678e-16]
])
actual_output = task_func(self.data_small, n_components=2).values
np.testing.assert_almost_equal(actual_output, expected_output, decimal=5)
flipped = -expected
transformed_data = task_func(self.data_small, n_components=2).values
self.assertTrue(
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
"The PCA results do not match the expected values considering possible sign flips."
)
8 changes: 6 additions & 2 deletions data/processed/93_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@ def test_values(self):
expect_tuples = [tuple(map(float, item.split(','))) for item in expect]
# Assert each pair of tuples is approximately equal
for actual, expected in zip(df_tuples, expect_tuples):
self.assertAlmostEqual(actual[0], expected[0], places=7, msg="DataFrame contents should match the expected output")
self.assertAlmostEqual(actual[1], expected[1], places=7, msg="DataFrame contents should match the expected output")
try:
self.assertAlmostEqual(actual[0], expected[0], places=7, msg="DataFrame contents should match the expected output")
self.assertAlmostEqual(actual[1], expected[1], places=7, msg="DataFrame contents should match the expected output")
except:
self.assertAlmostEqual(actual[0], -expected[0], places=7, msg="DataFrame contents should match the expected output")
self.assertAlmostEqual(actual[1], -expected[1], places=7, msg="DataFrame contents should match the expected output")
8 changes: 6 additions & 2 deletions data/raw/f_1727_junda_james.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ def test_values(self):

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

def run_tests():
"""Run all tests for this function."""
Expand Down
9 changes: 6 additions & 3 deletions data/raw/f_1776_junda_james.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ def test_return_types(self):
for a, b in zip(df_list, expect):
a1, a2 = str(a).split(',')
b1, b2 = str(b).split(',')
self.assertAlmostEqual(float(a1), float(b1), places=7)
self.assertAlmostEqual(float(a2), float(b2), places=7)
# self.assertEqual(df_list, expect, "DataFrame contents should match the expected output")
try:
self.assertAlmostEqual(float(a1), float(b1), places=7)
self.assertAlmostEqual(float(a2), float(b2), places=7)
except:
self.assertAlmostEqual(float(a1), -float(b1), places=7)
self.assertAlmostEqual(float(a2), -float(b2), places=7)

def test_invalid_input_empty_dataframe(self):
with self.assertRaises(ValueError):
Expand Down
18 changes: 10 additions & 8 deletions data/raw/f_247_indraneil.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ def test_case_5(self):
self.assertIsInstance(result, np.ndarray)
self.assertEqual(result.shape, (10, 2))
# Test the return value
# Expected result (can have flipped signs)
expected = np.array([
[-7.79, 0.], [-6.06, 0.], [-4.33, 0.], [-2.6, 0.], [-0.87, 0.],
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, 0.], [7.79, 0.]
])

# Check if either the original or the sign-flipped version matches
flipped = -expected
self.assertTrue(
np.allclose(
result,
[
[-7.79, 0.], [-6.06, 0.], [-4.33, -0.], [-2.6, -0.], [-0.87, -0.],
[0.87, 0.], [2.6, 0.], [4.33, 0.], [6.06, -0.], [7.79, 0.]
],
atol=0.1
)
np.allclose(result, expected, atol=0.1) or np.allclose(result, flipped, atol=0.1),
"The PCA results do not match the expected values considering possible sign flips."
)


Expand Down
10 changes: 7 additions & 3 deletions data/raw/f_405_jenny.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,19 @@ def test_case_8(self):
data = [[2, 3], [3, 4], [5, 6]]
_, transformed_data = f_405(data)
# Using the sklearn PCA output as the expected transformation
expected_transformation = np.array(
expected = np.array(
[
[-1.88561808e00, 1.93816421e-16],
[-4.71404521e-01, 3.32511118e-16],
[2.35702260e00, 2.21555360e-16],
]
)
np.testing.assert_almost_equal(
transformed_data, expected_transformation, decimal=5

# Check if either the original or the sign-flipped version matches
flipped = -expected
self.assertTrue(
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
"The PCA results do not match the expected values considering possible sign flips."
)

def test_case_9(self):
Expand Down
8 changes: 6 additions & 2 deletions data/raw/f_565_niklas.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ def test_case_4(self):
def test_case_5(self):
transformed_data = f_565([(-1, -1, -1), (0, 0, 0), (1, 1, 1)], 1)
self.assertEqual(transformed_data.shape, (3, 1))
self.assertTrue(transformed_data[0][0] < 0)
self.assertTrue(transformed_data[1][0] == 0)
self.assertTrue(transformed_data[2][0] > 0)
try:
self.assertTrue(transformed_data[0][0] < 0)
self.assertTrue(transformed_data[2][0] > 0)
except:
self.assertTrue(transformed_data[0][0] > 0)
self.assertTrue(transformed_data[2][0] < 0)

run_tests()
if __name__ == "__main__":
Expand Down
11 changes: 7 additions & 4 deletions data/raw/f_719_simon.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,19 @@ def test_empty_dataframe(self):
f_719(data_empty)

def test_known_input(self):
expected_output = np.array([
expected = np.array([
[ 2.82842712e+00, 3.64856517e-16],
[ 1.41421356e+00, -1.21618839e-16],
[-0.00000000e+00, 0.00000000e+00],
[-1.41421356e+00, 1.21618839e-16],
[-2.82842712e+00, 2.43237678e-16]
])
actual_output = f_719(self.data_small, n_components=2).values
np.testing.assert_almost_equal(actual_output, expected_output, decimal=5)

flipped = -expected
transformed_data = f_719(self.data_small, n_components=2).values
self.assertTrue(
np.allclose(transformed_data, expected, atol=0.1) or np.allclose(transformed_data, flipped, atol=0.1),
"The PCA results do not match the expected values considering possible sign flips."
)

def run_tests():
suite = unittest.TestSuite()
Expand Down
Loading

0 comments on commit 2c8136a

Please sign in to comment.