[Tutor] Built In Functions
Rafael Knuth
rafael.knuth at gmail.com
Tue Dec 17 17:23:08 CET 2013
I just wrote a unittest for this function here:
def PositiveCalculator(*summands):
if all(x > 0 for x in summands):
return sum(summands)
else:
raise ValueError("negative value")
Here's the test (I want to test whether the function works if the user
enters floats instead of integers) :
import unittest
from all_any import PositiveCalculator
class TestCalculator(unittest.TestCase):
def test_floats(self):
self.assertTrue(PositiveCalculator(3.45, 54.3, 5.62))
if __name__ == " __main__":
unittest.main()
For some reason the test runs through without giving me any output,
and I was wondering what I am doing wrong here?
Raf
On Tue, Dec 17, 2013 at 4:56 PM, Rafael Knuth <rafael.knuth at gmail.com> wrote:
>>> def check_values(a, b):
>>> if all(number >= 0 for number in range(a, b)):
>>> return True
>>> else:
>>> raise ValueError("negative number")
>>>
>>> And:
>>> def PositiveCalculator(a, b):
>>> if a > 0 and b > 0:
>>> return a + b
>>> else:
>>> raise ValueError("negative number")
>>
>>
>> So zero is now considered a negative number?
>
> Thanks ;-)
> if a >= 0 and b >= 0
More information about the Tutor
mailing list