Coverage for src/sandbox/fibonacci.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-10-01 21:36 +0000

1from typing import List 

2 

3 

4class Fibonacci: 

5 """Fibonacci sequence methods.""" 

6 

7 @staticmethod 

8 def calculate(nth: int) -> int: 

9 """Calculate the n-th Fibonacci number. 

10 

11 An extended description of Fibonacci numbers can go here. 

12 

13 Parameters 

14 ---------- 

15 nth 

16 Number of Fibonacci sequence to calculate. 

17 

18 Returns 

19 ------- 

20 int 

21 Value of n-th Fibonacci number. 

22 """ 

23 

24 num_a, num_b = 0, 1 

25 

26 for _ in range(nth): 

27 num_a, num_b = num_b, num_a + num_b 

28 

29 return num_a 

30 

31 @staticmethod 

32 def get_values(nth: int) -> List: 

33 """Returns the Fibonacci sequence up until n-th number. 

34 

35 Parameters 

36 ---------- 

37 nth 

38 Number of Fibonacci sequence to calculate. 

39 

40 Returns 

41 ------- 

42 list 

43 Fibonacci numbers. 

44 """ 

45 

46 return [Fibonacci.calculate(i) for i in range(1, nth + 1)]