fixed assertions to fetch Exceptions and assert message

This commit is contained in:
2025-04-01 23:55:33 +03:00
parent 28b59bb2e7
commit d683ff8165
3 changed files with 14 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
import sys
import pytest
from io import StringIO
from nordhealth_test.solution import print_pairs_with_same_sum
@@ -43,13 +44,15 @@ def test_no_valid_pairs():
# 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
expected_output = "No pairs can be formed from the input file."
with pytest.raises(ValueError) as val_error:
capture_output(print_pairs_with_same_sum, arr)
assert str(val_error.value) == 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
expected_output = "No pairs can be formed from the input file."
with pytest.raises(ValueError) as val_error:
capture_output(print_pairs_with_same_sum, arr)
assert str(val_error.value) == expected_output