"Kepala Pening" <[EMAIL PROTECTED]> wrote

However, to have limit = 2, perhaps I should do
while b <= limit.

Thanks Alan for pointing it out.

No probs, forgetting to test both ends of the range is a common mistake.

In fact good testing practice says that for any range of values
you should test

- the lowest legal value - correct result
- one lower than the lowest - fails gracefully
- much lower than lowest - fails gracefully
- a mid range value - correct result
- the highest legal value - correct value
 (Of course testing the "highest possible value" would be tricky
 in your case! :-)
- one higher than the highest - fails gracefully
- much higher than the legal limit - fails gracefully
- an invalid value - fails gracefully (eg in your case limit = 'four')

So that's at least 8 tests for every range parameter/variable
in your code.
Automated testing is "A Good Thing" :-)

Alan G.



----- Original Message -----
From: "Alan Gauld" <[EMAIL PROTECTED]>
To: tutor@python.org
Date: Thu, 31 Jul 2008 06:39:32 +0100
Subject: Re: [Tutor] Memory error - how to manage large data sets?


"Kepala Pening" <[EMAIL PROTECTED]> wrote

> def sumEvenFibonacci( limit ):
> a, b = 1, 1  # don't waste with a = 0
> sum = 0
> while b < limit:
> if b%2 == 0: sum += b
> a, b = b, a + b
> return sum
>
> print sumEvenFibonacci( 2000000 )

Does it work for limit = 2?

Alan G.





_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to