Mercurial > hg > pyloader
changeset 38:f6616a5f468f
test fibonacci sequence
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 07 Jun 2011 19:17:21 -0700 |
parents | 5268ab85fe1b |
children | db095765807d |
files | tests/objects.py tests/test.ini tests/test_ini.txt |
diffstat | 3 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/objects.py Tue Jun 07 19:14:04 2011 -0700 +++ b/tests/objects.py Tue Jun 07 19:17:21 2011 -0700 @@ -39,6 +39,6 @@ def fib(n): """return the nth fibonacci term""" sequence = [1,1] - while len(sequence) < n: - sequence.append(sequence[len(sequence)-1], sequence[len(sequence)-2]) + while len(sequence) - 1 < n: + sequence.append(sequence[len(sequence)-1] + sequence[len(sequence)-2]) return sequence[n]
--- a/tests/test.ini Tue Jun 07 19:14:04 2011 -0700 +++ b/tests/test.ini Tue Jun 07 19:17:21 2011 -0700 @@ -5,5 +5,7 @@ [callback:%(here)s/objects.py:stringsort] +[fibonacci:%(here)s/objects.py:fib] + [@:%(here)s/objects.py:wrap] app = %(object)s
--- a/tests/test_ini.txt Tue Jun 07 19:14:04 2011 -0700 +++ b/tests/test_ini.txt Tue Jun 07 19:17:21 2011 -0700 @@ -24,3 +24,11 @@ >>> callback = inifactory.load('callback') >>> callback('foo', 'bar') 'abfoor' + +Lets test the Fibonnaci sequence:: + + >>> fib = inifactory.load('fibonacci') + >>> fib(0) == fib(1) == 1 + True + >>> [fib(i) for i in range(5)] + [1, 1, 2, 3, 5]