From 99a9593a96e0393c4d2391396feef3fa00a34be7 Mon Sep 17 00:00:00 2001 From: Malte Schokolowski <baw8441@uni-hamburg.de> Date: Sat, 1 Jan 2022 20:24:57 +0100 Subject: [PATCH] added unit tests for update_depth.py --- verarbeitung/test/update_graph_unittest.py | 38 ++++++++++++++++++-- verarbeitung/update_graph/update_depth.py | 40 ++++++++++++++++------ 2 files changed, 65 insertions(+), 13 deletions(-) diff --git a/verarbeitung/test/update_graph_unittest.py b/verarbeitung/test/update_graph_unittest.py index 63cc288..59de002 100644 --- a/verarbeitung/test/update_graph_unittest.py +++ b/verarbeitung/test/update_graph_unittest.py @@ -9,7 +9,7 @@ from verarbeitung.construct_new_graph.initialize_graph import init_graph_constru from verarbeitung.construct_new_graph.export_to_json import output_to_json from verarbeitung.update_graph.import_from_json import input_from_json from verarbeitung.update_graph.update_graph import update_graph, get_old_input_dois, get_new_input_dois -from verarbeitung.update_graph.update_depth import reduce_max_height_depth_test, get_old_height_depth +from verarbeitung.update_graph.update_depth import reduce_max_height_depth_test, get_old_max_references_citations_test from verarbeitung.get_pub_from_input import input_test_func class UpdatingTest(unittest.TestCase): @@ -66,8 +66,8 @@ class UpdatingTest(unittest.TestCase): # hard to test because we only have dois as test objects and no urls variant def test_get_new_input_dois(self): - new_dois = ['pub_lg_2_i', 'pub_lg_1_i', 'pub_lg_c_i'] - self.assertCountEqual(get_new_input_dois(new_dois, True), ['pub_lg_2_i', 'pub_lg_1_i', 'pub_lg_c_i']) + new_dois = ['doi_lg_2_i', 'doi_lg_1_i', 'doi_cg_i'] + self.assertCountEqual(get_new_input_dois(new_dois, True), ['doi_lg_2_i', 'doi_lg_1_i', 'doi_cg_i']) # update_depth.py: @@ -104,6 +104,38 @@ class UpdatingTest(unittest.TestCase): self.assertCountEqual(reduce_max_height_depth_test(pubs, 1, "Depth"), [pub_lg_2_i, pub_lg_2_d_11, pub_lg_2_h_11, pub_lg_2_h_21]) self.assertCountEqual(reduce_max_height_depth_test(pubs, 0, "Depth"), [pub_lg_2_i, pub_lg_2_h_11, pub_lg_2_h_21]) + def test_get_old_max_references(self): + pub_lg_2_i = input_test_func('doi_lg_2_i') + pub_lg_2_i.group = 0 + pub_lg_2_h_11 = input_test_func('doi_lg_2_h11') + pub_lg_2_h_11.group = 1 + pub_lg_2_d_11 = input_test_func('doi_lg_2_d11') + pub_lg_2_d_11.group = -1 + pub_lg_2_h_21 = input_test_func('doi_lg_2_h21') + pub_lg_2_h_21.group = 2 + pub_lg_2_d_21 = input_test_func('doi_lg_2_d21') + pub_lg_2_d_21.group = -2 + pub_lg_2_d_22 = input_test_func('doi_lg_2_d22') + pub_lg_2_d_22.group = -2 + pubs = [pub_lg_2_i, pub_lg_2_h_11, pub_lg_2_h_21, pub_lg_2_d_11, pub_lg_2_d_21, pub_lg_2_d_22] + self.assertCountEqual(get_old_max_references_citations_test(pubs, 2, "Depth"), [pub_lg_2_d_21,pub_lg_2_d_22]) + + def test_get_old_max_citations(self): + pub_lg_2_i = input_test_func('doi_lg_2_i') + pub_lg_2_i.group = 0 + pub_lg_2_h_11 = input_test_func('doi_lg_2_h11') + pub_lg_2_h_11.group = 1 + pub_lg_2_d_11 = input_test_func('doi_lg_2_d11') + pub_lg_2_d_11.group = -1 + pub_lg_2_h_21 = input_test_func('doi_lg_2_h21') + pub_lg_2_h_21.group = 2 + pub_lg_2_h_22 = input_test_func('doi_lg_2_h22') + pub_lg_2_h_22.group = 2 + pub_lg_2_d_21 = input_test_func('doi_lg_2_d21') + pub_lg_2_d_21.group = -2 + pubs = [pub_lg_2_i, pub_lg_2_h_11, pub_lg_2_h_21, pub_lg_2_h_22,pub_lg_2_d_11, pub_lg_2_d_21] + self.assertCountEqual(get_old_max_references_citations_test(pubs, 2, "Height"), [pub_lg_2_h_21,pub_lg_2_h_22]) + diff --git a/verarbeitung/update_graph/update_depth.py b/verarbeitung/update_graph/update_depth.py index ab4322a..1d99d5a 100644 --- a/verarbeitung/update_graph/update_depth.py +++ b/verarbeitung/update_graph/update_depth.py @@ -23,28 +23,48 @@ from .update_edges import back_to_valid_edges from input.publication import Publication -def reduce_max_height_depth_test(pubs, max_hd, hd_var): +def reduce_max_height_depth_test(pubs, max_dh, dh_var): ''' :param pubs: list of publication to reduce height/depth in :type pubs: List[Publication] - :param max_hd: new maximum height/depth to reduce publications in publication list to - :type max_hd: int + :param max_dh: new maximum depth/height to reduce publications in publication list to + :type max_dh: int - :param hd_var: defines if depth or height gets to be reduced - :type hd_var: String + :param dh_var: defines if depth or height gets to be reduced + :type dh_var: String for unit test purposes only ''' global processed_input_list processed_input_list = pubs - if hd_var == "Height": - reduce_max_height(max_hd) + if dh_var == "Height": + reduce_max_height(max_dh) else: - reduce_max_depth(max_hd) + reduce_max_depth(max_dh) return processed_input_list +def get_old_max_references_citations_test(pubs, old_dh, dh_var): + ''' + :param pubs: list of publication to reduce height/depth in + :type pubs: List[Publication] + + :param old_dh: old depth/height to get max references/citations + :type old_dh: int + + :param dh_var: defines if depth or height gets to be reduced + :type dh_var: String + + for unit test purposes only + ''' + global processed_input_list + processed_input_list = pubs + + if dh_var == "Height": + return(get_old_max_citations(old_dh, True)) + else: + return(get_old_max_references(old_dh, True)) def reduce_max_height(max_height): ''' @@ -96,7 +116,7 @@ def get_old_max_references(old_depth, test_var): ''' old_max_references = [] for pub in processed_input_list: - if (abs(pub.group) == old_depth): + if (pub.group == -old_depth): pub = get_pub(pub.doi_url, test_var) if (type(pub) != Publication): #print(pub) @@ -113,7 +133,7 @@ def get_old_max_citations(old_height, test_var): ''' old_max_citations = [] for pub in processed_input_list: - if (abs(pub.group) == old_height): + if (pub.group == old_height): pub = get_pub(pub.doi_url, test_var) if (type(pub) != Publication): #print(pub) -- GitLab