Sobes.tech
Senior

from file import ATM, SDK import pytest BILLS = {5000, 1000, 500, 100, 50} @pytest.mark.parametrize( "bills_count_const,expected", [ ({5000: 0, 1000: 0, 500: 0, 100: 0, 50: 0}, False), ({5000: 100, 1000: 100, 500: 100, 100: 100, 50: 100}, True) ] ) def test_false(bills_count_const, expected): atm = ATM(SDK()) atm.bills_count = bills_count_const amount = 1000 res = atm.withdraw(amount) assert res == expected return

sobes.tech AI

Answer from AI

This test uses pytest parameterization to check the withdraw method of the ATM class. The test verifies that when there are no bills (bills_count_const with values 0), the method returns False, and when there are many bills, it returns True.

The example shows how to substitute different ATM states and check the correctness of cash withdrawal.

Key points:

  • @pytest.mark.parametrize allows running the test with different input data.
  • atm.bills_count sets the current number of bills by denominations.
  • The withdraw(amount) method should return a boolean indicating whether the withdrawal was successful.

Example of using parameterization:

@pytest.mark.parametrize(
    "input,expected",
    [
        ({5000: 1, 1000: 0}, True),
        ({5000: 0, 1000: 0}, False),
    ]
)
def test_withdraw(input, expected):
    atm = ATM(SDK())
    atm.bills_count = input
    assert atm.withdraw(5000) == expected

This helps cover different scenarios without code duplication.