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
72 lines (56 loc) · 2.45 KB
/
Copy pathtest_hello.py
File metadata and controls
72 lines (56 loc) · 2.45 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
63
64
65
66
67
68
69
70
71
72
import unittest
import hello
import numpy as np
class TestHello(unittest.TestCase):
def test_hello(self):
self.assertEqual(hello.hello(), "Hello, world!")
def test_sin(self):
self.assertAlmostEqual(hello.sin(0), 0, places = 4)
self.assertAlmostEqual(hello.sin(np.pi), 0, places = 4)
self.assertAlmostEqual(hello.sin(1), 0.8415, places = 4)
def test_cos(self):
self.assertEqual(hello.cos(0), 1)
self.assertEqual(hello.cos(np.pi), -1)
self.assertAlmostEqual(hello.cos(1), 0.5403, places = 4)
def test_tan(self):
self.assertAlmostEqual(hello.tan(0), 0, places = 4)
self.assertAlmostEqual(hello.tan(np.pi), 0, places = 4)
hello.tan(np.pi/2).assertRaises(ValueError)
def test_cot(self):
self.assertAlmostEqual(hello.cot(np.pi/2), 0, places = 4)
self.assertAlmostEqual(hello.cot(np.pi*3/2), 0, places = 4)
hello.cot(0).assertRaises(ValueError)
def test_add(self):
self.assertEqual(hello.add(1, 1), 2)
self.assertEqual(hello.add(1, -1), 0)
self.assertEqual(hello.add(12345, 54321), 66666)
def test_sub(self):
self.assertEqual(hello.sub(1, 1), 0)
self.assertEqual(hello.sub(1, -1), 2)
self.assertEqual(hello.sub(12345, 54321), -41976)
def test_mul(self):
self.assertEqual(hello.mul(1, 1), 1)
self.assertEqual(hello.mul(3, -2), -6)
self.assertEqual(hello.mul(-8, -23), 184)
def test_div(self):
self.assertEqual(hello.div(1, 1), 1)
self.assertEqual(hello.div(1, -1), -1)
self.assertAlmostEqual(hello.div(64, 3), 21.3333, places = 4)
def test_pow(self):
self.assertEqual(hello.power(6, 3), 216)
self.assertAlmostEqual(hello.power(6, -1), 0.1667, places = 4)
self.assertEqual(hello.power(-2, 5), -32)
def test_root(self):
self.assertEqual(hello.sqrt(9), 3)
self.assertAlmostEqual(hello.sqrt(2), 1.414, places = 3)
self.assertEqual(hello.sqrt(1522756), 1234)
def test_exp(self):
self.assertEqual(hello.exp(0), 1)
self.assertAlmostEqual(hello.exp(2), 7.389, places = 3)
self.assertAlmostEqual(hello.exp(-3), 0.0498, places = 3)
def test_log(self):
self.assertEqual(hello.log(1), 0)
self.assertAlmostEqual(hello.log(123), 2.0899, places = 4)
hello.log(0).assertRaises(ValueError)
if __name__ == "__main__":
unittest.main()