[Tutor] Memory error - how to manage large data sets?

Alan Gauld alan.gauld at btinternet.com
Fri Aug 1 00:31:06 CEST 2008


"Kepala Pening" <kepalapening at gmail.com> 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" <alan.gauld at btinternet.com>
> To: tutor at python.org
> Date: Thu, 31 Jul 2008 06:39:32 +0100
> Subject: Re: [Tutor] Memory error - how to manage large data sets?
>
>>
>> "Kepala Pening" <kepalapening at gmail.com> 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 at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list