Ejemplo n.º 1
0
def test_fib_eighth():
    """Test eight Fibonacci number.
    
    Note that this test highlights the convenience of defining a
    main function in a script file. Normally one would call this
    script from the command line via bash. Here we call it directly
    and redirect the output (stdout) to a string that we can test.
    """
    # First redirect stdout to a string
    out = io.StringIO()
    with contextlib.redirect_stdout(out):
        # then run the script with commandline argument "6"
        # note that argument 0 is always the program name itself
        fib.main(["./fib.py", "6"])
    # then check printed output in string, stripping newline characters
    assert out.getvalue().strip() == "8"
Ejemplo n.º 2
0
def test1():
    """
    verify that the main function operates as intended. 
    first simulate a command line input and check if the main function can test if the input is correct, and 
    then check if the fib() function can return expected outcome
    """

    argvList = ["fib.py", "5"]  #simulate the command line arguments

    expectedList = [1, 1, 2, 3, 5]
    retList = fib.main(argvList)

    assert type(retList) == list

    print(retList)

    assert len(retList) == len(expectedList)

    assert expectedList == retList
    print("test1 success")

    return
Ejemplo n.º 3
0
# Import various modules
import fib
import os
number = 300
result = fib.fib_gen(number)
print(result)
fib.main(
)  # know from where is executed, here it is executed from fib which is imported
""" Output the result to a text file """
file = open("fibseries.txt", "w")
for each_item in result:
    file.write(str(each_item) + " ")
file.close()
""" Current location of the directory """
current_location = os.getcwd()
print(current_location)
Ejemplo n.º 4
0
def main(val):
	print("Output of",val) # Display the specified value
	fact.main(val) # Calculate and output Factorial number
	fib.main(val) # Calculate and output Fibonacci sequence
Ejemplo n.º 5
0
def test_fib():
    result  = fib.main(10)
    correct = 55
    assert result == correct
Ejemplo n.º 6
0
 def test_fib():
     assert fib.main(16)==987