2015-07-01 18:48:04 +08:00
|
|
|
from nose.tools import assert_equal
|
|
|
|
|
|
|
|
|
|
|
|
class TestFib(object):
|
2015-07-06 18:15:53 +08:00
|
|
|
|
2015-07-01 18:48:04 +08:00
|
|
|
def test_fib(self, func):
|
|
|
|
result = []
|
2016-07-11 12:12:10 +08:00
|
|
|
expected = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
|
|
|
|
for i in range(len(expected)):
|
2015-07-01 18:48:04 +08:00
|
|
|
result.append(func(i))
|
2016-07-11 12:12:10 +08:00
|
|
|
assert_equal(result, expected)
|
2015-07-01 18:48:04 +08:00
|
|
|
print('Success: test_fib')
|
|
|
|
|
2015-07-12 03:35:34 +08:00
|
|
|
|
2015-07-01 18:48:04 +08:00
|
|
|
def main():
|
|
|
|
test = TestFib()
|
2017-01-23 01:06:58 +08:00
|
|
|
math = Math()
|
|
|
|
test.test_fib(math.fib_recursive)
|
|
|
|
test.test_fib(math.fib_dynamic)
|
|
|
|
test.test_fib(math.fib_iterative)
|
2015-07-01 18:48:04 +08:00
|
|
|
|
2015-07-12 03:35:34 +08:00
|
|
|
|
2015-07-01 18:48:04 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|