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
  • Last modified: 2024/02/07 06:46
  • by msuter