forked from blksail-edu/python-refresher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hello.py
More file actions
62 lines (45 loc) · 1.76 KB
/
test_hello.py
File metadata and controls
62 lines (45 loc) · 1.76 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import unittest
import hello
class TestHello(unittest.TestCase):
def test_hello(self):
self.assertEqual(hello.hello(), "Hello, world!")
self.assertNotEqual(hello.hello(), "Hello, friend!")
def test_add(self):
self.assertEqual(hello.add(1,2), 3)
self.assertNotEqual(hello.add(1,3),5)
def test_sub(self):
self.assertEqual(hello.sub(2,1),1)
self.assertNotEqual(hello.sub(1,3),-3)
def test_mul(self):
self.assertEqual(hello.mul(3,3), 9)
self.assertNotEqual(hello.mul(3,4), 9)
def test_div(self):
self.assertEqual(hello.div(6,3), 2)
with self.assertRaises(ValueError):
hello.div(1,0)
def test_sqrt(self):
self.assertEqual(hello.sqrt(9), 3)
self.assertNotEqual(hello.sqrt(16),2)
def test_power(self):
self.assertEqual(hello.power(3,2),9)
self.assertNotEqual(hello.power(4,3),63)
def test_log(self):
self.assertEqual(round(hello.log(7.3890561), 1), 2)
self.assertNotEqual(round(hello.log(54.59815),1),6)
def test_exp(self):
self.assertEqual(round(hello.exp(2), 7), 7.3890561)
self.assertNotEqual(round(hello.exp(5),6),150)
def test_sin(self):
self.assertEqual(hello.sin(0), 0)
self.assertEqual(hello.sin(1), 0.8414709848078965)
def test_cos(self):
self.assertEqual(hello.cos(0), 1)
self.assertEqual(hello.cos(1), 0.5403023058681398)
def test_tan(self):
self.assertEqual(hello.tan(0), 0)
self.assertEqual(hello.tan(1), 1.5574077246549023)
def test_cot(self):
self.assertEqual(hello.cot(0), float("inf"))
self.assertEqual(hello.cot(1), 0.6420926159343306)
if __name__ == "__main__":
unittest.main()