-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_maths.py
More file actions
45 lines (38 loc) · 1.35 KB
/
test_maths.py
File metadata and controls
45 lines (38 loc) · 1.35 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
import unittest
import maths
class TestMaths(unittest.TestCase):
def test_list_int(self):
# Test that it can sum a list of integers
data = [1, 2, 3, 4, 5]
result = maths.my_sum(data)
self.assertEqual(15, result)
other_data = [6, 7, 8, 9, 10]
result = maths.my_sum(other_data)
self.assertEqual(40, result)
def test_multiply_2_numbers(self):
result = maths.my_multiply(2, 4)
self.assertEqual(8, result)
result = maths.my_multiply(7, 9)
self.assertEqual(63, result)
def test_square(self):
result = maths.my_square(3)
self.assertEqual(9, result)
result = maths.my_square(5)
self.assertEqual(25, result)
def test_cube(self):
result = maths.my_cube(3)
self.assertEqual(27, result)
result = maths.my_cube(5)
self.assertEqual(125, result)
def test_factorial(self):
# Use the built-in function
result = maths.factorial(5)
self.assertEqual(120, result)
result = maths.factorial(6)
self.assertEqual(720, result)
def test_factorial_with_recursion(self):
# Write your own recursion
result = maths.factorial_with_recursion(6)
self.assertEqual(720, result)
result = maths.factorial_with_recursion(7)
self.assertEqual(5040, result)