# Path: smarkets/functools.py
# def always_return(value):
#     def fun(*args, **kwargs):
#         return value
#     return fun
# 
# def memoized(fun):
#     storage = {}
# 
#     @wraps(fun)
#     def wrapper(*args, **kwargs):
#         key = (args, tuple(iteritems(kwargs)))
#         try:
#             value = storage[key]
#         except KeyError:
#             value = storage[key] = fun(*args, **kwargs)
#         return value
#     return wrapper


from nose.tools import eq_
from smarkets.functools import always_return, memoized
from __future__ import absolute_import, division, print_function, unicode_literals




def test_memoized():
    @memoized
    def my_sum(x, y):
        counter[0] += 1
        return x + y

    counter = [0]
    eq_(my_sum(1, 2), 3)
    eq_(counter[0], 1)
    eq_(my_sum(1, 2), 3)
    eq_(counter[0], 1)

    counter = [0]
    eq_(my_sum(1, y=2), 3)
    eq_(counter[0], 1)
    eq_(my_sum(1, y=2), 3)
    eq_(counter[0], 1)


def test_always_return():

# Path: smarkets/functools.py
# def always_return(value):
#     def fun(*args, **kwargs):
#         return value
#     return fun
# 
# def memoized(fun):
#     storage = {}
# 
#     @wraps(fun)
#     def wrapper(*args, **kwargs):
#         key = (args, tuple(iteritems(kwargs)))
#         try:
#             value = storage[key]
#         except KeyError:
#             value = storage[key] = fun(*args, **kwargs)
#         return value
#     return wrapper


# Path: smarkets/tests/functools.py
from nose.tools import eq_
from smarkets.functools import always_return, memoized

from __future__ import absolute_import, division, print_function, unicode_literals




def test_memoized():
    @memoized
    def my_sum(x, y):
        counter[0] += 1
        return x + y

    counter = [0]
    eq_(my_sum(1, 2), 3)
    eq_(counter[0], 1)
    eq_(my_sum(1, 2), 3)
    eq_(counter[0], 1)

    counter = [0]
    eq_(my_sum(1, y=2), 3)
    eq_(counter[0], 1)
    eq_(my_sum(1, y=2), 3)
    eq_(counter[0], 1)


def test_always_return():

    fun = always_return(42)