forked from realpython/materials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegersums.py
More file actions
executable file
·33 lines (23 loc) · 809 Bytes
/
integersums.py
File metadata and controls
executable file
·33 lines (23 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
""" Sum of Integers Up To n
Write a function, add_it_up, which returns the sum of the integers from 0
to the single integer input parameter.
The function should return 0 if a non-integer is passed in.
"""
import unittest
def add_it_up(n):
# TODO: Your code goes here!
return n
class IntegerSumTestCase(unittest.TestCase):
def test_to_ten(self):
results = [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
for n in range(10):
self.assertEqual(add_it_up(n), results[n])
def test_string(self):
self.assertEqual(add_it_up("testing"), 0)
def test_float(self):
self.assertEqual(add_it_up(0.124), 0)
def test_negative(self):
self.assertEqual(add_it_up(-19), 0)
if __name__ == "__main__":
unittest.main()