Python/Jython Unittest

Thanks, I appreciate it. From the script console I was able to get an alternative calll working, as I suspected something along the lines of command line/main call.

import unittest

def fib(n):
	""" Calculates the n-th Fibonacci number iteratively 
	
	>>> fib(0)
	0
	>>> fib(1)
	1
	>>> fib(10) 
	55
	>>> fib(40)
	102334155
	>>> 
	
	"""
	a, b = 0, 1
	for i in range(n):
		a, b = b, a + b
	return a


	
class FibonacciTests(unittest.TestCase):
    def test_Dummy(self):
		self.assertEqual([0,3.3,'FOIL',5.01],[0,3.3,'FOIL',5.01])
		
    def test_Calculation(self):
        self.assertEqual(fib(0), 0)
        self.assertEqual(fib(1), 0)
        self.assertEqual(fib(5), 5)
        self.assertEqual(fib(10), 55)
        self.assertEqual(fib(20), 6765)

	
suite = unittest.TestLoader().loadTestsFromTestCase(FibonacciTests)
output = unittest.TextTestRunner(verbosity=2).run(suite)

if output.wasSuccessful():
	print 'Passed tests.'
else:
	number_failed = len(output.failures) + len(output.errors)
	print "Failed "+str(number_failed)+ " test(s)"
1 Like