Skriver ut testfallets namn
This commit is contained in:
+18
-1
@@ -31,9 +31,15 @@ class TestTowerOfHanoi(unittest.TestCase):
|
||||
"""
|
||||
|
||||
def test_valid_input(self):
|
||||
print("=========================")
|
||||
print("test_valid_input:")
|
||||
self.assertEqual(tower_of_hanoi(3, 'A', 'B', 'C'), None) # Example with 3 disks
|
||||
print("=========================\n")
|
||||
|
||||
def test_edge_case_single_disk(self):
|
||||
print("=========================")
|
||||
print("test_edge_case_single_disk:")
|
||||
print("=========================\n")
|
||||
expected_output = "Move disk 1 from A to C\n"
|
||||
captured_output = io.StringIO()
|
||||
sys.stdout = captured_output
|
||||
@@ -42,24 +48,35 @@ class TestTowerOfHanoi(unittest.TestCase):
|
||||
self.assertEqual(captured_output.getvalue(), expected_output)
|
||||
|
||||
def test_invalid_input_zero_disks(self):
|
||||
print("=========================")
|
||||
print("test_invalid_input_zero_disks:")
|
||||
with self.assertRaises(ValueError):
|
||||
tower_of_hanoi(0, 'A', 'B', 'C')
|
||||
print("=========================\n")
|
||||
|
||||
def test_prompt_for_integer_valid(self):
|
||||
print("=========================")
|
||||
print("test_prompt_for_integer_valid:")
|
||||
with io.StringIO("3\n") as mock_stdin:
|
||||
sys.stdin = mock_stdin
|
||||
self.assertEqual(prompt_for_integer(), 3)
|
||||
print("\n=========================\n")
|
||||
|
||||
def test_prompt_for_integer_invalid_negative(self):
|
||||
print("=========================")
|
||||
print("test_prompt_for_integer_invalid_negative:")
|
||||
with io.StringIO("-2\n1\n") as mock_stdin:
|
||||
sys.stdin = mock_stdin
|
||||
self.assertEqual(prompt_for_integer(), 1) # Should eventually get a valid integer
|
||||
|
||||
print("\n=========================\n")
|
||||
|
||||
def test_prompt_for_integer_invalid_string(self):
|
||||
print("=========================")
|
||||
print("test_prompt_for_integer_invalid_string:")
|
||||
with io.StringIO("abc\n3\n") as mock_stdin:
|
||||
sys.stdin = mock_stdin
|
||||
self.assertEqual(prompt_for_integer(), 3) # Should eventually get a valid integer
|
||||
print("\n=========================\n")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user