Exemple #1
0
 def test_fib(self):
     sequence_number = 3
     start_pointa = 0
     start_pointb = 1
     expected_result = 1
     self.assertEqual(fib(sequence_number, start_pointa, start_pointb),
                      expected_result)
Exemple #2
0
def test_fib() -> None:
    """Example function with types documented in the docstring.

    `PEP 484`_ type annotations are supported. If attribute, parameter, and
    return types are annotated according to `PEP 484`_, they do not need to be
    included in the docstring:

    Args:
        param1 (int): The first parameter.
        param2 (str): The second parameter.

    Returns:
        bool: The return value. True for success, False otherwise.

    .. _PEP 484:
        https://www.python.org/dev/peps/pep-0484/

    """
    assert fib(0) == 0
    assert fib(1) == 1
    assert fib(2) == 1
    assert fib(3) == 2
    assert fib(4) == 3
    assert fib(5) == 5
    assert fib(10) == 55
Exemple #3
0
def test_fib() -> None:
    assert fib(0) == 0
    assert fib(1) == 1
    assert fib(2) == 1
    assert fib(3) == 2
    assert fib(4) == 3
    assert fib(5) == 5
    assert fib(10) == 55
Exemple #4
0
 def test_fib(self):
     f = fib(50)
     c = 2
     print f
     self.assertTrue(f[0] == 0)
     self.assertTrue(f[1] == 1)
     while c <= (len(f) - 1):
         if c > 1:
             if not f[c] == 1:
                 self.assertTrue(f[c] > f[c-1])
             self.assertTrue(f[c] == (f[c-1] + f[c-2]))
         c+=1
     print "F**k yeah!"
 def test_0(self):
     self.assertEqual(fib(0), 1)
     self.assertEqual(fib(1), 1)
with a section header and a colon followed by a block of indented text.

Example:
    Examples can be given using either the ``Example`` or ``Examples``
    sections. Sections support any reStructuredText formatting, including
    literal blocks::

        $ python

Section breaks are created by resuming unindented text. Section breaks
are also implicitly created anytime a new section starts.

Attributes:
    module_level_variable1 (int): Module level variables may be documented in
        either the ``Attributes`` section of the module docstring, or in an
        inline docstring immediately following the variable.

        Either form is acceptable, but the two should not be mixed. Choose
        one convention to document module level variables and be consistent
        with it.
"""


import sys

from {{cookiecutter.repo_name}}.{{cookiecutter.repo_name}} import fib

if __name__ == "__main__":
    n = int(sys.argv[1])
    print(fib(n))
Exemple #7
0
def test_fib_complex():
    with pytest.raises(TypeError):
        obs = fib(9 + 7j)
 def test_4(self):
     self.assertEqual(fib(7), 21)
     self.assertEqual(fib(8), 34)
     self.assertEqual(fib(9), 55)
Exemple #9
0
    while a < n:
        result.append(a)
        a, b = b, a+b
    return result
#Now enter the Python interpreter and import this module with the following command:
>>>import fibo

#This does not enter the names of the functions defined in fibo directly in the current symbol table; it only enters the module name fibo there. Using the module name you can access the functions:
>>> fibo.fib(1000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
>>> fibo.fib2(100)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]

#More in Module:
>>> from fibo import *
>>> fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

#If the module name is followed by as, then the name following as is bound directly to the imported module.
>>> import fibo as fib
>>> fib.fib(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

#It can also be used when utilising from with similar effects:
>>> from fibo import fib as fibonacci
>>> fibonacci(500)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
 
Standard Modules:

# importing sqrt() and factorial from the 
Exemple #10
0
#!/usr/bin/env python
#
# Pablo Munoz (c) 2018
#
# Example use of fortran wrapper
#
import numpy as np
from fib import *

# Print doc generated by f2py
print(fib.__doc__)

# Use
print(fib(10))
print()

# Use matrix multiplication
N = 100
A = np.eye(N)
B = np.random.rand(N, N)

if not np.testing.assert_array_equal(np.dot(A, B), B):
    print('PYTHON  matrix multiplication test OK')

# Explicit or implicit matrix dimensions
if not np.testing.assert_array_equal(matmul(A, B, N, N, N), B):
    print('FORTRAN OK matrix multiplication explicit dimension test ')

if not np.testing.assert_array_equal(matmul(A, B), B):
    print('FORTRAN OK matrix multiplication implicit dimension test ')
Exemple #11
0
def test_fib0():
    obs = fib(0)
    assert obs == 1
Exemple #12
0
def test_fib1():
    # test edge 1
    obs = fib(1)
    assert obs == 1
Exemple #13
0
Output: I am Rahul
        I am Ashish
        I am Randheer
        I am Arun

# write Fibonacci series up to n
>>> def fib(n):    
...     """Print a Fibonacci series up to n."""  #function’s documentation string, or docstring
...     a, b = 0, 1
...     while a < n:
...         print(a, end=' ')
...         a, b = b, a+b

>>> # Now call the function we just defined:
... fib(2000)
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597

>>> f = fib
>>> f(100)
0 1 1 2 3 5 8 13 21 34 55 89

#a function that returns a list of the numbers of Fibonacci series, instead of printing it
>>> def fib2(n):  # return Fibonacci series up to n
...     """Return a list containing the Fibonacci series up to n."""
...     result = []
...     a, b = 0, 1
...     while a < n:
...         result.append(a)    # see below
...         a, b = b, a+b
...     return result
def test_fib(n, result):
    assert fib(n) == result
Exemple #15
0
#!/usr/bin/python

import fib
from fib import fib

print "Type the Fibonacci number you would like to see\n -1 to quit\n"

while 1:
    num = raw_input("Enter your Input: ")
    if (num < 0 or not num.isdigit()):
        print "Quiting..."
        break
    print "At ", num, " Fibonacci Number is ", fib(int(num))
Exemple #16
0
import fibo

print dir(fibo)
# ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'fib', 'fib2']

print fibo.fib(1000)
# 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

print fibo.fib(100)
# [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]

print fibo.__name__
# 'fibo'

fib = fibo.fib
print fib(500)
# 1 1 2 3 5 8 13 21 34 55 89 144 233 377

reload(fibo)
import fibo as fib
print fib.fib(500)
# 1 1 2 3 5 8 13 21 34 55 89 144 233 377

reload(fibo)
from fibo import fib as fibonacci
print fibonacci(500)
# 1 1 2 3 5 8 13 21 34 55 89 144 233 377

# would not encourage this usage
reload(fibo)
from fibo import *
Exemple #17
0
from C:\Python27\APA_files\fib_number_list.py import fib

__author__ = 'apa'

n = 100

fib(n)
Exemple #18
0
class MyEmptyClass:
    pass

def initlog(*args):
    pass # Remember to implement this!

def fib(n):
    '''Print a Fibonacci series up to n.'''
    a, b = 0, 1 # double assignment so cool!
    while a < n:
        print(a, end=' ')
        a, b = b, a+b
    print()

fib(2000)

def foo(name, **kwargs):
    return 'name' in kwargs

#def foo(name,/,**kwargs):
#    return 'name' in kwargs

def concat(*args, sep="/"):
    return sep.join(args)

def concatalso(*args, sep="-"):
    return sep.join(args)

def parrot(voltage, state='a stiff', action='voom'):
    print("-- This parrot wouldn't", action, end=' ')
Exemple #19
0
 def test(self):
     self.assertEqual(fib(14), 24)
Exemple #20
0
def test_fib0():
    # test edge 0
    obs = fib(0)
    assert obs == 1
Exemple #21
0
def test_fib0():
    obs = fib(0)
    exp = 1
    assert obs == exp
Exemple #22
0
def test_fib6():
    obs = fib(6)
    assert obs == 13
def fibTest(data_fib) -> None:
    assert fib(data_fib[0]) == data_fib[1]
Exemple #24
0
def test_fib1():
    obs = fib(1)
    assert obs == 1
Exemple #25
0
def fib(n):
    if n < 2:
        return 1
    else:
        return fib(n-1) + fib(n-2)
Exemple #26
0
def main(args):
    if len(args) > 0:
        print(fib(int(args[0])))
        return
    raise Exception("Input argument expected.")
 def test_1(self):
     self.assertEqual(fib(2), 2)
def test_fib():
    assert fib(1) == 1
    assert fib(2) == 1
    assert fib(7) == 13
    with pytest.raises(AssertionError):
        fib(-10)
 def test_2(self):
     self.assertEqual(fib(3), 3)
Exemple #30
0
import fibo
fibo.fib(1000)
print(fibo.fib2(100))
print(fibo.__name__)
# 导入模块的其他方式
from fibo import *  #  * 导入模块的全部关键字
fib(500)
print(fib2(1000))

import fibo as fib  # 导入模块里的fib关键字
fib.fib(500)

from fibo import fib as fibonacci  # 导入fib关键字,用fibonacci代替
fibonacci(500)
 def test_3(self):
     self.assertEqual(fib(4), 5)
     self.assertEqual(fib(5), 8)
     self.assertEqual(fib(6), 13)