def Stress_Test(N): while True: n = random.randint(1, N) print(n) faster_fib = calc_fib(n) naive_fib_n = naive_fib(n) if faster_fib == naive_fib_n: print("OK!") else: assert faster_fib == naive_fib_n, f"{faster_fib}, {naive_fib_n}"
def stress_test_fib(): res1 = 0 res2 = 0 while True: a = random.randint(1, 100) # b = random.randint(1, 10) res1 = fib.calc_fib(a) res2 = fib.fib_fast(a) print("a: ", a) if res1 == res2: print("OK") else: print("WRONG calc_fib: {}, fib_fast:{}".format(res1, res2)) break print()
def test_2(self): self.assertEqual(1, calc_fib(2))
def run_rand(): N = int(input('How many test cases? : ')) f = int(input('Average fibonacci index? : ')) for i in range(N): num = random.randint(int(f/10),f*2) fibonacci.calc_fib(num)
def test_0(self): self.assertEqual(0, calc_fib(0))
def test_1(self): self.assertEqual(1, calc_fib(1))
def test_3(self): self.assertEqual(2, calc_fib(3))
def test_39(self): self.assertEqual(63245986, calc_fib(39))
def test_when_position_negative(self): with self.assertRaises(ValueError): calc_fib(-1) calc_fib(-42)
import fibonacci import fibonacci_fast import random if __name__=="__main__": n= random.randrange(15) a=[] while(True): #for i in range(n+1): # a.append(random.randrange(10)) #print(a) result1 = fibonacci.calc_fib(n) result2 = fibonacci_fast.fast_fib(n) if result1==result2: print ("OK") else: print("n="+str(n)) print("fib= "+str(result1)+" fast_fib= "+str(result2) ) break
def test_calc_fib(n, fib): assert calc_fib(n) == fib
#git config --global core.autocrlf true from fibonacci import calc_fib from fibonacciNumber import calc_fib_mine import random iterations = 1 while True: n = random.randint(0, 40) if calc_fib(n) == calc_fib_mine(n): print("Good Job!") else: print("Wrong") break iterations += 1 print(iterations)
def test_zero(self): self.assertEqual(0, calc_fib(1))
def test_six(self): self.assertEqual(8, calc_fib(6))
# Uses python3 import fibonacci n = int(input()) print(fibonacci.calc_fib(n))
from argparse import ArgumentParser from pathlib import Path from sys import stdout from fibonacci import calc_fib import time import io parser = ArgumentParser() parser.add_argument("-d", "--digits", type=int, help="number of digit to calculate", default=5) parser.add_argument("-o", "--out", type=Path, help="where to save the calculated Fibonacci sequence") parser.add_argument("-e", "--exclusively", type=bool, help="output only one element of the Fibonacci sequence") args = parser.parse_args() stream = io.open(args.out, "w", encoding="utf-8") if isinstance(args.out, Path) else stdout start_time = time.time_ns() calc_fib(args.digits, lambda digit: stream.write(f"{digit} "), not args.exclusively) end_time = time.time_ns() stream.write("\r\n") if isinstance(args.out, Path): print(f"Saved Fibonacci sequence to {args.out}") exec_time = {"s": (end_time-start_time) // 1000000000, "ms": ((end_time-start_time) - (end_time-start_time) // 1000000000) / 1000000} print("Execution time: {:.0f}s {:.3f}ms".format(exec_time['s'], exec_time['ms']))
def test_when_position_lte_1(self): self.assertEqual(calc_fib(0), 0) self.assertEqual(calc_fib(1), 1)
def fib_last_digit(n): return fibonacci.calc_fib(n % 60) % 10
def test_when_position_gt_1(self): self.assertEqual(calc_fib(4), 3) self.assertEqual(calc_fib(5), 5) self.assertEqual(calc_fib(9), 34) self.assertEqual(calc_fib(14), 377) self.assertEqual(calc_fib(21), 10946)