Example #1
0
def findNsuccessiveElem(fiboFct, fiboParam, memoize=None):
    startElem = fiboParam[0]
    endElem = fiboParam[1]

    start = time.time()
    Lresult = list()

    if fiboFct == fibonacci.fib31 or fiboFct == fibonacci.fib32:
        f3 = fibonacci.fib3()
        for i in range(startElem):
            f3.next()

    for i in range(startElem, endElem):
        if memoize is None:
            if fiboFct == fibonacci.fib31 or fiboFct == fibonacci.fib32:
                Lresult.append(f3.next())
            else:
                Lresult.append(fiboFct(i))
        elif isinstance(memoize, dict):
            if fiboFct == fibonacci.fib31 or fiboFct == fibonacci.fib32:
                Lresult.append(f3.next())
            else:
                Lresult.append(fiboFct(i, memoize))
        elif hasattr(memoize, '__call__'):
            if fiboFct == fibonacci.fib31 or fiboFct == fibonacci.fib32:
                Lresult.append(f3.next())
            else:
                Lresult = memoize(fiboFct, i)

    duration = time.time() - start

    return duration, Lresult
Example #2
0
def test_fib2():
    fun = fib2(1000)
    lst2 = []
    while True:
        n = fun()
        if n != None:
            lst2.append(n)
        else:
            break
    assert lst2 == list(fib3(1000))
Example #3
0
 def wibble():
     return f.fib3(n)
 def test_fib3(self):
     self.assertEqual(fib3(1), 1)
Example #5
0
def test_fibonacci3():
    # The quicker function
    for i, fib_i in answers:
        assert f.fib3(i) == fib_i