from task_3 import has_intersection, get_intersection def test_case_1(): test = [ [1594705106, 1594706480], [1594705158, 1594705773], [1594705849, 1594706480], ] result = [ [1594705106, 1594706480], [1594705158, 1594705773], ] # print(f"{test=}") answer = enlarge_elapsed_intervals(test) assert answer == result, f"Error in test_case_1:\n{answer} \n {result}" def test_case_2(): test = [ [1594705106, 1594706480], [1594705106, 1594706490], [1594705849, 1594706495], ] result = [ [1594705106, 1594706490], [1594705849, 1594706495], ] # print(f"{test=}") answer = enlarge_elapsed_intervals(test) assert answer == result, f"Error in test_case_1:\n{answer}\n {result}" def test_case_3(): test = [ [21, 30], [25, 32], [33, 40], [33, 35], [41, 45], [42, 43], [44, 45], [46, 50], [47, 51], ] result = [ [21, 32], [33, 40], [41, 45], [46, 51], ] answer = [] for i in range(len(test)): for k in range(i, len(test)): a = find_inner_sum_of_intersections(test[i], test[k]) answer.append(a) print(f"{answer=}") answer = [a for a in answer if a] test.extend(answer) print("!___") print(test) answer = enlarge_elapsed_intervals(test) print(f"{answer=}") assert answer == result, f"Error in test_case_1:\n{answer}\n {result}" def test_case_4(): test = [ [21, 30], [33, 40], [33, 35], # [41, 45], [42, 43], # [44, 45], # ] result = [ [21, 30], [33, 40], [41, 45], ] answer = absorb_small_included_intervals(test) assert answer == result, f"Error in test_case_4:\n{answer}\n {result}" def test_case_5(): test = [ [21, 30], # [28, 40], # [33, 35], [41, 45], [42, 43], [44, 45], [53, 60], [51, 55], ] result = [ [21, 40], [41, 45], [51, 60], ] answer = get_extended_intervals(test) assert answer == result, f"Error in extend_intervals:\n{answer}\n {result}" def absorb(): test = [ [21, 30], [33, 40], [33, 35], # [41, 45], [42, 43], # [44, 45], # ] result = [ [21, 30], [33, 40], [41, 45], ] test_b = {i[0]: i[1] for i in test} beg = [test[k] for k, v in enumerate(test_b) if test[k][1] < test_b[v]] test_e = {i[1]: i[0] for i in test} end = [test[k] for k, v in enumerate(test_e) if test[k][0] > test_e[v]] print(beg, end) def inters(): print(has_intersection([21, 25], [22, 30])) print(has_intersection([22, 30], [21, 25])) print(has_intersection([21, 25], [26, 30])) print(has_intersection([26, 30], [21, 25])) def inters2(): print(get_intersection([21, 25], [22, 30])) print(get_intersection([22, 30], [21, 25])) print(get_intersection([22, 30], [31, 33])) if __name__ == "__main__": # test_case_1() # test_case_2() # test_case_3() # test_case_4() # test_case_5()\ # absorb() # inters() inters2()