import sys from io import StringIO from nordhealth_test.solution import print_pairs_with_same_sum def capture_output(func, *args, **kwargs): captured_output = StringIO() sys.stdout = captured_output func(*args, **kwargs) sys.stdout = sys.__stdout__ return captured_output.getvalue() # Test case Input 1: [6, 4, 12, 10, 22, 54, 32, 42, 21, 11] def test_input_1(): arr = [6, 4, 12, 10, 22, 54, 32, 42, 21, 11] expected_output = ( "Pairs : ( 4, 12) ( 6, 10) have sum : 16\n" "Pairs : ( 10, 22) ( 21, 11) have sum : 32\n" "Pairs : ( 12, 21) ( 22, 11) have sum : 33\n" "Pairs : ( 22, 21) ( 32, 11) have sum : 43\n" "Pairs : ( 32, 21) ( 42, 11) have sum : 53\n" "Pairs : ( 12, 42) ( 22, 32) have sum : 54\n" "Pairs : ( 10, 54) ( 22, 42) have sum : 64\n" ) result = capture_output(print_pairs_with_same_sum, arr) assert result == expected_output # Test case Input 2: [4, 23, 65, 67, 24, 12, 86] def test_input_2(): arr = [4, 23, 65, 67, 24, 12, 86] expected_output = ( "Pairs : ( 4, 86) ( 23, 67) have sum : 90\n" ) result = capture_output(print_pairs_with_same_sum, arr) assert result == expected_output # Test case: Array with no valid pairs def test_no_valid_pairs(): arr = [1, 2, 3, 5] expected_output = "" result = capture_output(print_pairs_with_same_sum, arr) assert result == expected_output # Test case: Array with exactly one element def test_single_element(): arr = [10] expected_output = "No pairs can be formed from the input file.\n" result = capture_output(print_pairs_with_same_sum, arr) assert result == expected_output # Test case: Empty array def test_empty_array(): arr = [] expected_output = "No pairs can be formed from the input file.\n" result = capture_output(print_pairs_with_same_sum, arr) assert result == expected_output