def test_reduce_node_quantity_custom_ex(): nodes_len = 2 column_names = ["№", "neighbors", "S"] data = [ ["1", "2,3,4", 2], ["2", "1,3,5", 4], ["3", "1,2,4,5", 6], ["4", "1,3,5", 8], ["5", "2,3,4,13,16", 10], ["6", "7,8,9", 1.01], ["7", "6,8,10", 1.02], ["8", "6,7,9,11", 1.03], ["9", "6,8,12", 1.04], ["10", "7,11,13", 1.05], ["11", "8,10,12,14", 1.06], ["12", "9,11,15", 1.07], ["13", "5,10,14,17", 1.08], ["14", "11,13,15", 1.09], ["15", "12,14", 1.10], ["16", "5,17", 50], ["17", "13,16", 50], ] dataframe = pd.DataFrame(data=data, columns=column_names) solver = Solver(data=dataframe, given_sum=20, number_of_clusters=4) solver._reduce_nodes_quantity(graph=solver.crop_map.graph, nodes_quantity=nodes_len) assert len( solver.crop_map.graph) == nodes_len, f"{len(solver.crop_map.graph)=}" test_cluster_connected = Cluster( serial_num=0, nodes_belong=[x for x in solver.crop_map.graph.values()]) assert solver._check_cluster_for_connectivity( graph=solver.crop_map.graph, cluster=test_cluster_connected)
def test_reduce_node_quantity_basic(): """ придумать реальный кейс для проверки на связность :return: """ global data nodes_len = 20 data = pd.read_excel(datapath) solver = Solver(data=data, given_sum=20, number_of_clusters=4) solver._reduce_nodes_quantity(graph=solver.crop_map.graph, nodes_quantity=nodes_len) assert len( solver.crop_map.graph) == nodes_len, f"{len(solver.crop_map.graph)=}" test_cluster_connected = Cluster( serial_num=0, nodes_belong=[x for x in solver.crop_map.graph.values()]) assert solver._check_cluster_for_connectivity( graph=solver.crop_map.graph, cluster=test_cluster_connected)