solutions

Class counter

Create a class Cookie that keeps track of how many instances were created. The Cookie class should have a count method that returns how many Cookie objects where instantiated. It should also include other method reset_counter that puts the count back to 0. Example:

Cookie.count()  # 0

c1 = Cookie()
c2 = Cookie()
c3 = Cookie()
Cookie.count()  # 3

c4 = Cookie()
c5 = Cookie()

Cookie.count()  # 5

# == COUNTER RESET ==
Cookie.reset_counter()

Cookie.count()  # 0

c6 = Cookie()
c7 = Cookie()
Cookie.count()  # 2

Test Cases

test basic counter - Run Test

def test_basic_counter():
    # Starts with 0
    Cookie.count() == 0

    # We create 2 cookies
    c = Cookie()
    c = Cookie()

    # Now counter == 2
    Cookie.count() == 2

    # We now reset the counter
    Cookie.reset_counter()

    # Count is back to 0
    Cookie.count() == 0

    # But if we create a few more cookies:

    c = Cookie()
    c = Cookie()
    c = Cookie()
    c = Cookie()

    # Counter is still counting
    Cookie.count() == 4