Skip to content

Commit

Permalink
v0.2.21
Browse files Browse the repository at this point in the history
  • Loading branch information
yh202109 committed Jul 28, 2024
1 parent ac358ea commit 7622d06
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions tests/test_cdt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import unittest
import pandas as pd
from mtbp3.util.cdt import diff_2cols_in_1df, diff_2cols_in_2df
from mtbp3.util import cdt

class TestCdt(unittest.TestCase):
def setUp(self):
Expand All @@ -13,47 +13,45 @@ def setUp(self):

def test_diff_2cols_in_1df_with_difference(self):
expected_output = pd.DataFrame({'ARM': [3], 'ACTARM': [5], 'diff': ['True']})
result = diff_2cols_in_1df(self.df)
result = cdt.diff_2cols_in_1df(self.df)
self.assertTrue(isinstance(result, pd.DataFrame))
self.assertEqual(len(result), len(self.df))

def test_diff_2cols_in_1df_without_difference(self):
tmpdf = self.df[['ARM', 'ARM']]
tmpdf.columns = ['ARM', 'ACTARM']
result = diff_2cols_in_1df(tmpdf)
result = cdt.diff_2cols_in_1df(tmpdf)
self.assertTrue(result.empty)

def test_diff_2cols_in_1df_invalid_input(self):
expected_output = "Input is not a DataFrame."
result = diff_2cols_in_1df("not a dataframe")
result = cdt.diff_2cols_in_1df("not a dataframe")
self.assertEqual(result, expected_output)

def test_diff_2cols_in_1df_missing_column(self):
expected_output = "Column 'COL' does not exist in the DataFrame."
result = diff_2cols_in_1df(self.df, col1='COL')
result = cdt.diff_2cols_in_1df(self.df, col1='COL')
self.assertEqual(result, expected_output)

def test_diff_2cols_in_2df_with_existing_column(self):
expected_output = pd.DataFrame({'gp_1': ['1', '3'], 'gp_2': ['1', '3'], 'source_1': ['True', 'True'], 'source_2': ['True', 'True'], 'count': [1, 2]})
result = diff_2cols_in_2df(self.df1, self.df2, 'col', 'gp')
result = cdt.diff_2cols_in_2df(self.df1, self.df2, 'col', 'gp')
self.assertTrue(isinstance(result, pd.DataFrame))
# self.assertEqual(result.to_dict(), expected_output.to_dict())

def test_diff_2cols_in_2df_with_non_existing_column(self):
expected_output = "Column 'non_existing_col' not found in both dataframes."
result = diff_2cols_in_2df(self.df1, self.df2, 'non_existing_col', 'gp')
result = cdt.diff_2cols_in_2df(self.df1, self.df2, 'non_existing_col', 'gp')
self.assertEqual(result, expected_output)

def test_diff_2cols_in_2df_with_non_existing_group(self):
expected_output = "Group 'non_existing_gp' not found in both dataframes."
result = diff_2cols_in_2df(self.df1, self.df2, 'col', 'non_existing_gp')
result = cdt.diff_2cols_in_2df(self.df1, self.df2, 'col', 'non_existing_gp')
self.assertEqual(result, expected_output)

def test_diff_2cols_in_2df_with_same_group_and_column(self):
expected_output = "Columns 'gp' and 'col' should be different columns."
result = diff_2cols_in_2df(self.df1, self.df2, 'gp', 'gp')
result = cdt.diff_2cols_in_2df(self.df1, self.df2, 'gp', 'gp')
self.assertEqual(result, expected_output)


if __name__ == "__main__":
unittest.main()

0 comments on commit 7622d06

Please sign in to comment.