# Path: mamba/core/decorators.py
# def cache(size=16):
#     def decorator(func):
#         def wrapper(*args, **kwargs):
# def unlimited_cache(func):
#     def wrapper(*args, **kwargs):


from twisted.trial import unittest
from mamba.core import decorators


hit_count = 0


class TestDecorators(unittest.TestCase):

    def setUp(self):
        global hit_count
        hit_count = 0

    def test_cache_is_cahing(self):

        @decorators.cache(size=16)
        def multiplication(a, b):
            global hit_count
            hit_count += 1

            return a * b

        self.assertEqual(multiplication(2, 2), 4)
        self.assertEqual(hit_count, 1)
        self.assertEqual(multiplication(2, 2), 4)
        self.assertEqual(hit_count, 1)
        self.assertEqual(multiplication(4, 4), 16)
        self.assertEqual(hit_count, 2)

    def test_cache_limit_works(self):
        global hit_count


# Path: mamba/core/decorators.py
# def cache(size=16):
#     def decorator(func):
#         def wrapper(*args, **kwargs):
# def unlimited_cache(func):
#     def wrapper(*args, **kwargs):


# Path: mamba/test/test_decorators.py
from twisted.trial import unittest
from mamba.core import decorators



hit_count = 0


class TestDecorators(unittest.TestCase):

    def setUp(self):
        global hit_count
        hit_count = 0

    def test_cache_is_cahing(self):

        @decorators.cache(size=16)
        def multiplication(a, b):
            global hit_count
            hit_count += 1

            return a * b

        self.assertEqual(multiplication(2, 2), 4)
        self.assertEqual(hit_count, 1)
        self.assertEqual(multiplication(2, 2), 4)
        self.assertEqual(hit_count, 1)
        self.assertEqual(multiplication(4, 4), 16)
        self.assertEqual(hit_count, 2)

    def test_cache_limit_works(self):
        global hit_count


        @decorators.cache(size=2)