-
Notifications
You must be signed in to change notification settings - Fork 9
/
02.py
30 lines (22 loc) · 906 Bytes
/
02.py
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
#! /usr/bin/env python
from __future__ import print_function
# Author: Victor Terron (c) 2015
# Email: `echo vt2rron1iaa32s | tr 132 @.e`
# License: GNU GPLv3
""" Write a function that, given a list of integers, returns the product of
all the elements. You are not allowed to use neither a for nor a while loop. """
import unittest
def product(numbers):
pass # place magic here
class ProductTests(unittest.TestCase):
def test_product(self):
self.assertEqual( 1, product([]))
self.assertEqual( 0, product([0]))
self.assertEqual( 1, product([1]))
self.assertEqual( 5, product([5, 1]))
self.assertEqual( -6, product([3, -2]))
self.assertEqual( 6, product([-3, -2]))
self.assertEqual( 30, product([2, 3, 5]))
self.assertEqual(362880, product(range(1, 10)))
if __name__ == "__main__":
unittest.main()