def test_fibonacci(): """ test the function fibonacci(n) """ assert fibonacci(9) == 34, 'incorrect' assert fibonacci(6) == 8, 'incorrect'
def test_fibonacci(): n = 5 out = recursion.fibonacci(n) assert out == 8 n = 6 out = recursion.fibonacci(n) assert out == 13
def test_fibonacci(): n = 5 out = recursion.fibonacci(n) assert out == 5 n = 7 out = recursion.fibonacci(n) assert out == 13 n = 1 out = recursion.fibonacci(n) assert out == 1 n = 2 out = recursion.fibonacci(n) assert out == 1
def main(): n = input('Print fibonacci numbers upto which nth term?') n = int(n) for i in range(0, n): print(fibonacci(i), end=' ') print('\n')
def test_fibonacci_with_large_integers(self): # These could run for a long time, depending on your implementation... assert fibonacci(15) == 610 assert fibonacci(20) == 6765 assert fibonacci(25) == 75025 # TODO: Improve the runtime of your fibonacci function for these cases # If you're not careful, you may need to be very patient for these... assert fibonacci(30) == 832040 assert fibonacci(35) == 9227465 assert fibonacci(40) == 102334155 assert fibonacci(100) == 354224848179261915075 assert fibonacci(200) == 280571172992510140037611932413038677189525 assert fibonacci(300) == \ 222232244629420445529739893461909967206666939096499764990979600
def main(): n = input('Upto which number do you want to print all fibonacci numbers? ') n = int(n) x = 0 while True: fib_series_term = fibonacci(x) if fib_series_term > n: break else: print(fib_series_term, end=' ') x = x + 1 print('\n')
def test_fibonacci_with_floating_point_numbers(self): # Should raise a ValueError for non-integer n with self.assertRaises(ValueError): fibonacci(2.0) with self.assertRaises(ValueError): fibonacci(3.14159) with self.asesertRaises(ValueError): fibonacci('5')
def test_fibonacci_with_large_integers(self): # These could run for a long time, depending on your implementation... assert fibonacci(15) == 610 assert fibonacci(20) == 6765 assert fibonacci(25) == 75025 # If you're not careful, you may need to be very patient for these... assert fibonacci(30) == 832040 assert fibonacci(35) == 9227465 assert fibonacci(40) == 102334155
def test_functions(): """ make sure all functions work correctly """ assert factorial(4) == 24, 'incorrect' assert fibonacci(8) == 21, 'incorrect' assert reverse( 'A sentence that has to be reversed by the reverse function' ) == 'noitcnuf esrever eht yb desrever eb ot sah taht ecnetnes A', 'incorrect' assert sum_array([[5, 5], [20], [2, 1]]) == 33, 'incorrect' assert bubble_sort([59, 69, 3, 58, 494, 4, 13, 30]) == [59, 3, 58, 69, 4, 13, 30, 494], 'incorrect' #lists to test merge_sort function x = [34, 5, 2, 6] y = [12, 34, 54, 1] assert merge_sort(x + y) == [1, 2, 5, 6, 12, 34, 34, 54], 'incorrect' assert quick_sort([5, 6, 3, 7, 11, 44]) == [3, 5, 6, 7, 11, 44], 'incorrect'
def test_fibonacci_with_floating_point_numbers(self): # fibonacci should raise a ValueError for non-integer n with self.assertRaises(ValueError, msg='function undefined for float'): fibonacci(2.0) fibonacci(3.14159)
def test_fibonacci_with_large_integers(self): # these could run for a long time... assert fibonacci(15) == 610 assert fibonacci(20) == 6765 assert fibonacci(25) == 75025
def test_fibonacci_with_negative_integers(self): # fibonacci should raise a ValueError for n < 0 with self.assertRaises(ValueError, msg='function undefined for n < 0'): fibonacci(-1) fibonacci(-5)
n = 5 print "The factorial of", n, "is", recursion.factorial(n) short_list = [0,1,2,3,4,5,6,7,8,9,10] print "In the list", short_list, "there are/is", recursion.count_list(short_list), "element(s)." list_to_add = [0,1,2,3,4,5] print "The sum of the list", list_to_add, "is", recursion.sum_list(list_to_add) list_to_reverse = [9,8,7,6,5,4,3,2,1] print "The reverse of", list_to_reverse, "is", recursion.reverse(list_to_reverse) x = 10 print "The", x, "th Fibonacci number is", recursion.fibonacci(x) list_to_search = [6,7,8] element = 8 print "I will attempt to find the element", element, "in the list", list_to_search, "." print "If found, I will return the element; otherwise I will print 'None'." print "Result:", recursion.find(list_to_search, element) def isPalindrome(word): if recursion.palindrome(word): print "The word", word, "is a palindrome!" else: print "The word", word, "is not a palindrome." isPalindrome("racecar")
def test_fibonacci_with_small_integers(self): # fibonacci should return fibonacci(n-1) + fibonacci(n-2) for n >= 0 assert fibonacci(0) == 0 # base case assert fibonacci(1) == 1 # base case assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 assert fibonacci(6) == 8 assert fibonacci(7) == 13 assert fibonacci(8) == 21 assert fibonacci(9) == 34 assert fibonacci(10) == 55
def test_when_n_is_zero(self): self.assertEqual(r.fibonacci(0), 0)
def test_fibonacci_list(self): fib_list = [fibonacci(num) for num in range(14)] self.assertEqual(fib_list, self.fib_results)
from recursion import sum_array, factorial, reverse, fibonacci from sorting import bubble_sort, merge_sort, quick_sort print(sum_array([1, 2, 3])) print(fibonacci(10)) print(factorial(5)) print(reverse("abcdef")) print(bubble_sort([5, 4, 1, 2, 4, 9])) print(merge_sort([1, 3, 2, 5, 4, 7, 6])) print(quick_sort([3, 2, 4, 5, 7, 6]))
def test_when_n_is_one(self): self.assertEqual(r.fibonacci(1), 1)
def test_fibonacci_with_small_integers(self): # Known fibonacci numbers with small integer arguments assert fibonacci(0) == 0 # base case assert fibonacci(1) == 1 # base case assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 assert fibonacci(6) == 8 assert fibonacci(7) == 13 assert fibonacci(8) == 21 assert fibonacci(9) == 34 assert fibonacci(10) == 55
from recursion import sum_array, factorial, reverse, fibonacci from sorting import bubble_sort, merge_sort, quick_sort assert sum_array([1,2,3]) == 6 assert factorial(5) == 120 assert reverse('hello world') == 'dlrow olleh' assert fibonacci(3) = 1 assert bubble_sort([1,3,5,2,4]) == [1, 2, 3, 4, 5] assert merge_sort([3,0,6,33,9]) == [0, 3, 6, 9, 33] assert quick_sort([3,1,7,54,2]) == [1, 2, 3, 7, 54]
def test_fibonacci_with_large_integers(self): # These could run for a long time, depending on your implementation... assert fibonacci(15) == 610
def test_when_n_is_greater_than_one(self): self.assertEqual(r.fibonacci(5), 5) self.assertEqual(r.fibonacci(8), 21) self.assertEqual(r.fibonacci(12), 144)
def test_fibonacci(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 assert fibonacci(7) == 13 assert fibonacci(8) == 21 assert fibonacci(15) == 610
def test_fibonacci(): result = [fibonacci(x) for x in range(10)] assert [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] == result
# We want to use the functions that we have declared in the recursion.py file import recursion # Writing data to a file my_file = open("test.txt", "w") my_file.write("This is some file content. Hello 403IT :D") my_file.close() my_file = open("test.txt", "r") my_string = my_file.read() print(my_string) # Write a limited part of Fibonacci sequence into a file called "Fibonacci.txt" fib_list = recursion.fibonacci(0, 1, 100) print(fib_list) my_file = open("Fibonacci.txt", "w") for num in fib_list: my_file.write(str(num)) my_file.write("\n") my_file.close()
def test_fibonacci(self): self.assertEqual(recursion.fibonacci(10), 34) self.assertEqual(recursion.fibonacci_slow(10), 34) self.assertEqual(recursion.fibonacci(2), 1) self.assertEqual(recursion.fibonacci_slow(2), 1)
#!/usr/bin/python import recursion # import recursion as rek # from recursion import * # from recursion import factorial # from recursion import fibonacci as fib print recursion.factorial(6) print recursion.fibonacci(5)
def test_fibonacci_with_negative_integers(self): # Should raise a ValueError for n < 0 with self.assertRaises(ValueError): fibonacci(-1) with self.assertRaises(ValueError): fibonacci(-5)
def test_fibonacci_with_medium_integers(self): assert fibonacci(11) == 89 assert fibonacci(12) == 144
def test_fibonacci(): assert fibonacci(0) == 0 assert fibonacci(1) == 1 assert fibonacci(4) == 3 assert fibonacci(8) == 21
def time_1(): return recursion.fibonacci(2000)