Skip to content

Commit 3e31fdf

Browse files
committed
Fix tests to match changes
1 parent 7e08789 commit 3e31fdf

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

tests.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def func():
4444
)._to_string() == f"tail_recursive(func=" + repr(func) + ").tail_call('first_arg', 2, [], first_kwarg='1', second_kwarg=2, third_kwarg={})"
4545

4646

47-
def test_nested_tail_call_mode_raises_exception_for_unknown_mode():
47+
def test_nested_tail_call_mode_raises_exception_for_unknown_feature_set():
4848

4949
with pytest.raises(ValueError) as excinfo:
5050
@tail_recursive(feature_set="not_a_feature_set")
@@ -55,7 +55,7 @@ def _():
5555
excinfo.value)
5656

5757

58-
def test_nested_tail_call_mode_converts_string_to_mode():
58+
def test_nested_tail_call_mode_converts_string_to_feature_set():
5959

6060
@tail_recursive(feature_set="full")
6161
def _():
@@ -380,3 +380,33 @@ def square_and_triangular_numbers(n):
380380

381381
assert square_and_triangular_numbers(3).square == 9
382382
assert square_and_triangular_numbers(3).triangular == 6
383+
384+
385+
def test_class_property():
386+
import functools
387+
388+
class MathStuff:
389+
390+
def __init__(self, n):
391+
self.n = n
392+
393+
@tail_recursive(feature_set="full")
394+
# Requires ``lru_cache`` because this version of fibonacci is highly inefficient.
395+
@functools.lru_cache
396+
def fibonacci(self, n):
397+
if n <= 1:
398+
return n
399+
return self.fibonacci.tail_call(self, n - 1) + self.fibonacci.tail_call(self, n - 2)
400+
401+
@property
402+
@tail_recursive
403+
def fib_of_n(self):
404+
return self.fibonacci.tail_call(self, self.n)
405+
406+
assert MathStuff(0).fib_of_n == non_recursive_fibonacci(0) == 0
407+
assert MathStuff(1).fib_of_n == non_recursive_fibonacci(1) == 1
408+
assert MathStuff(4).fib_of_n == non_recursive_fibonacci(4) == 3
409+
assert MathStuff(7).fib_of_n == non_recursive_fibonacci(7) == 13
410+
411+
n = sys.getrecursionlimit() + 1
412+
assert MathStuff(n).fib_of_n == non_recursive_fibonacci(n)

0 commit comments

Comments
 (0)