class TestMethods(unittest.TestCase): def setUp(self): self.fib = Fibonacci() def test_should_fibonacci__raise_exception_due_to_negative_number_of_months(self): with self.assertRaises(Exception): self.fib.compute(-1, 1) def test_should_fibonacci__raise_exception_due_to_negative_number_of_pairs(self): with self.assertRaises(Exception): self.fib.compute(1, -1) def test_should_fibonacci_zero_return_zero(self): self.assertEqual(0, self.fib.compute(0, 1)) def test_should_fibonacci_one_return_one(self): self.assertEqual(1, self.fib.compute(1, 1)) def test_should_fibonacci_of_two_return_one(self): self.assertEqual(1, self.fib.compute(2, 1)) def test_should_fibonacci_of_three_return_two(self): self.assertEqual(2, self.fib.compute(3, 1)) def test_should_fibonacci_of_four_return_three(self): self.assertEqual(3, self.fib.compute(4, 1)) def test_should_fibonacci_ROSALIND(self): self.assertEqual(19, self.fib.compute(5, 3)) def tearDown(self): print("Test probado con éxito")
def recursif_time(): f, times, iterations = Fibonacci(), [], [] for i in range(1, 35): begin = time.time() f.recursif(i) end = time.time() e_time = end - begin times.append(e_time) iterations.append(i) return (times, iterations)
def iteratif_super_time(): f, times, iterations = Fibonacci(), [], [] for i in range(1, 500, 5): begin = time.time() for j in range(0, 10000): f.iteratif_super(i) end = time.time() e_time = end - begin times.append(e_time) iterations.append(i) return (times, iterations)
def iteratif_lineair_time(): f, times, iterations = Fibonacci(), [], [] for i in range(1, 500, 5): start = time.time() for j in range(0, 10000): f.iteratif_lineair(i) end = time.time() e_time = end-start times.append(e_time) iterations.append(i) return (times, iterations)
def run_fib(): global fib_game nth = int(request.form['prompt']) title = 'Results:' fibonacci = Fibonacci(nth) results = fibonacci.run() return render_template('fibresults.html', the_title=title, the_results=results)
class FibonacciShouldReturn(TestCase): def setUp(self): self.fibonacci = Fibonacci() def test_zeroForFirstNumber(self): self.assertEqual(0, self.getNumberAtIndex(0)) def test_oneForSecondNumber(self): self.assertEqual(1, self.getNumberAtIndex(1)) def test_oneForThirdNumber(self): self.assertEqual(1, self.getNumberAtIndex(2)) def test_twoForFourthNumber(self): self.assertEqual(2, self.getNumberAtIndex(3)) def test_threeForFifthNumber(self): self.assertEqual(3, self.getNumberAtIndex(4)) def test_fiveForSixthNumber(self): self.assertEqual(5, self.getNumberAtIndex(5)) def test_hugeValueForFiftiethNumber(self): self.assertTrue(self.getNumberAtIndex(49) > 1000000000) def getNumberAtIndex(self, index): return self.fibonacci.generate(index + 1)[index]
def GetSequence(self): if self.method is 'Fibonacci': from Fibonacci import Fibonacci self.seq = Fibonacci(self.N) elif self.method is 'Farey': from Farey import Farey self.seq = Farey(self.N)
def main(): user_input = input("Please enter a number between 1 and 50: ") while not(user_input.isdigit()) or int(user_input) < 1 or \ int(user_input) > 50: user_input = input("Please enter a number between 1 and 50: ") n = int(user_input) print() print("The first", n, "term(s) of the Fibonacci sequence:") fib_obj = Fibonacci(n) for i in fib_obj: print(i, end=" ") print()
def optimize(self): if self.method is 'GoldenSearch': from GoldenSearch import GoldenSearch [self.min, self.xmin] = GoldenSearch([self.minv, self.maxv], self.func, self.tol) elif self.method is 'Fibonacci': from Fibonacci import Fibonacci [self.min, self.xmin] = Fibonacci([self.minv, self.maxv], self.func, self.tol) elif self.method is 'QuadraticInterpolation': from QuadraticInterpolation import QuadraticInterpolation [self.min, self.xmin] = QuadraticInterpolation( (self.minv + self.maxv) / 2., self.func, self.tol) elif self.method is 'NelderMead': from NelderMead import NelderMead [self.min, self.xmin] = NelderMead(self.func, self.tol, self.N) elif self.method is 'SteepestDescent': from SteepestDescent import SteepestDescent [self.min, self.xmin] = SteepestDescent([self.minv, self.maxv], self.func, self.funcp, self.tol, self.N)
from Fibonacci import Fibonacci soma = 0 i = 1 while (Fibonacci(i) < 4000000): if (Fibonacci(i) % 2 == 0): soma = soma + Fibonacci(i) i += 1 print(soma)
__author__ = 'tmarsha1' from Fibonacci import Fibonacci from Fibonacci import BruteForceEvenValueFibonacci from Fibonacci import OptimizedEvenValueFibonacci if __name__ == '__main__': max_value = 4000000 fibonacci = Fibonacci.Fibonacci(max_value) print("Sum of fibonacci values: %s" % '{:,}'.format(fibonacci.sum())) fibonacci = BruteForceEvenValueFibonacci.BruteForceEvenValueFibonacci( max_value) print("Sum of brute force even values: %s" % '{:,}'.format(fibonacci.sum())) fibonacci = OptimizedEvenValueFibonacci.OptimizedEvenValueFibonacci( max_value) print("Sum of optimized even values: %s" % '{:,}'.format(fibonacci.sum()))
from Evklid import Evklid from Power import Power from PrimaryNumberSearch import PrimaryNumberSearch from Eratosphen import Eratosphen from Fibonacci import Fibonacci import time evk_diff = Evklid() power = Power() primaryNumberSearch = PrimaryNumberSearch() eratosphen = Eratosphen() fibonacci = Fibonacci() # Evklid: NOD by diff # start = time.time() # evk_diff.nod_by_diff(123456789, 123) # end = time.time() # # print('Evklid: NOD by diff (123456789, 123): ' + str(round(end - start, 3)) + ' ms') # # # Evklid: NOD by mod # # start = time.time() # evk_diff.nod_by_mod(123456789, 123) # end = time.time() # # print('Evklid: NOD by mod (123456789, 123): ' + str(round(end - start, 3)) + ' ms') # # # Iterative power #
def fibonacci(): return Fibonacci()
def test2_generateSequence_Test(): fib = Fibonacci() fib.generateSequence(10) assert fib.fibonacciSeq == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
def test1_getFibonacciNumber_Test(): fib = Fibonacci() assert fib.getFibonacciNumber(5) == 3
def test4_generateSequence_Test(): fib = Fibonacci() fib.generateSequence(15) assert fib.fibonacciSeq == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]
def test3_getFibonacciNumber_Test(): fib = Fibonacci() assert fib.getFibonacciNumber(10) == 34
def setUp(self): self.fibonacci = Fibonacci()
def test_sum(self): fib = Fibonacci.Fibonacci(5) self.assertEqual(fib.sum(), 12)
def main(): t, n = args() a = Fibonacci() print(a.get_i())
def test_sequence(self): fib = Fibonacci.Fibonacci(20) self.assertEqual("[1, 1, 2, 3, 5, 8, 13]", str(fib))
''' This function contorl Parsing command line parameters ''' def get_command_line_arguments(): parser = argparse.ArgumentParser(description='Fibonacci nth order') parser.add_argument("fibonacciOrder", help="nth order of Fibonacci sequence") args = parser.parse_args() return args if __name__ == '__main__': generateNumberStringObj = CGenerateNumberString() args = get_command_line_arguments() fibonacciNthnumber = Fibonacci(int(args.fibonacciOrder)) if fibonacciNthnumber == -1: print("Error : Incorrect input") else: print("%s order of fibonacci sequence is %s" % (args.fibonacciOrder, fibonacciNthnumber)) numberString = BLANK_CHARACTER if fibonacciNthnumber == 0: numberString = ZERO_STRING else: numberString = generateNumberStringObj.convertNumberToString( fibonacciNthnumber) print("String representation of %s is %s" % (fibonacciNthnumber, numberString))
def showMessage(number='10'): return {'n':Fibonacci(int(number)),'n-1':Fibonacci(int(number)-1)}