4336a0cmodule-02(ex0): simplify test_temperature func
1 file changed, +14, -22
+14, -22
@@ -4,28 +4,20 @@ def input_temperature(temp_str: str) -> int:
4 4 def test_temperature() -> None:
5 5 print("=== Garden Temperature ===\n")
6 6
7 - # Test with valid input
8 - valid_input = "25"
9 - print(f"Input data is '{valid_input}'")
10 -
11 - try:
12 - temperature = input_temperature(valid_input)
13 - print(f"Temperature is now {temperature}°C")
14 - except ValueError as error:
15 - print(f"Caught input_temperature error: {error}")
16 -
17 - print()
18 - # Test with invalid input
19 - invalid_input = "abc"
20 - print(f"Input data is '{invalid_input}'")
21 -
22 - try:
23 - temperature = input_temperature(invalid_input)
24 - print(f"Temperature is now {temperature}°C")
25 - except ValueError as error:
26 - print(f"Caught input_temperature error: {error}")
27 -
28 - print("\nAll tests completed - program didn't crash!")
7+ test_inputs = ["25", "abc"]
8+
9+ for tmp in test_inputs:
10+ print(f"Input data is '{tmp}'")
11+
12+ try:
13+ temperature = input_temperature(tmp)
14+ print(f"Temperature is now {temperature}°C")
15+ except ValueError as error:
16+ print(f"Caught input_temperature error: {error}")
17+
18+ print()
19+
20+ print("All tests completed - program didn't crash!")
2921
3022
3123 if __name__ == "__main__":