solutions

Cookie Factory

Create a class Cookie with a class method create_cookies that receives a number as parameter and creates that amount of cookies. Example:

Cookie.create_cookies(3)
[<Cookie object>, <Cookie object>, <Cookie object>]

Cookie.create_cookies(1)
[<Cookie object>]

Cookie.create_cookies(5)
[<Cookie object>, <Cookie object>, <Cookie object>, <Cookie object>, <Cookie object>]

Test Cases

test create 5 cookies - Run Test

def test_create_5_cookies():
    cookies = Cookie.create_cookies(5)
    assert len(cookies) == 5

    cookie_1 = cookies[0]
    cookie_2 = cookies[1]
    cookie_3 = cookies[2]
    cookie_4 = cookies[3]
    cookie_5 = cookies[4]

    assert isinstance(cookie_1, Cookie)
    assert isinstance(cookie_2, Cookie)
    assert isinstance(cookie_3, Cookie)
    assert isinstance(cookie_4, Cookie)
    assert isinstance(cookie_5, Cookie)

test create 2 cookies - Run Test

def test_create_2_cookies():
    cookies = Cookie.create_cookies(2)
    assert len(cookies) == 2

    cookie_1 = cookies[0]
    cookie_2 = cookies[1]
    assert isinstance(cookie_1, Cookie)
    assert isinstance(cookie_2, Cookie)

test create 1 cookies - Run Test

def test_create_1_cookies():
    cookies = Cookie.create_cookies(1)
    assert len(cookies) == 1

    cookie_1 = cookies[0]
    assert isinstance(cookie_1, Cookie)