LU03.L01 - Kleinste und grösste Zahl finden

main_test.py
from main import random_numbers, user_input
 
 
def test_random(capsys):
    numbers = random_numbers()
    captured = capsys.readouterr()
    assert captured.out == f'{min(numbers)}\n{max(numbers)}\n'
 
 
def test_userinput_normal(capsys, monkeypatch):
    inputs = iter([31, -7, 258, 4, 0])
    monkeypatch.setattr('builtins.input', lambda _: next(inputs))
    user_input()
    captured = capsys.readouterr()
    assert captured.out == f'-7\n258\n'
 
 
def test_userinput_special(capsys, monkeypatch):
    inputs = iter([42, 0])
    monkeypatch.setattr('builtins.input', lambda _: next(inputs))
    user_input()
    captured = capsys.readouterr()
    assert captured.out == f'42\n42\n'

Marcel Suter

  • modul/m450/learningunits/lu03/loesungen/kleingross.txt
  • Zuletzt geändert: 2024/03/28 14:07
  • von 127.0.0.1