forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath_module.py
More file actions
80 lines (62 loc) · 1.55 KB
/
math_module.py
File metadata and controls
80 lines (62 loc) · 1.55 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
73
74
75
76
77
78
79
80
import math
from testutils import assertRaises
# assert(math.exp(2) == math.exp(2.0))
# assert(math.exp(True) == math.exp(1.0))
#
# class Conversible():
# def __float__(self):
# print("Converting to float now!")
# return 1.1111
#
# assert math.log(1.1111) == math.log(Conversible())
# roundings
assert int.__trunc__
assert int.__floor__
assert int.__ceil__
# assert float.__trunc__
with assertRaises(AttributeError):
assert float.__floor__
with assertRaises(AttributeError):
assert float.__ceil__
assert math.trunc(2) == 2
assert math.ceil(3) == 3
assert math.floor(4) == 4
assert math.trunc(2.2) == 2
assert math.ceil(3.3) == 4
assert math.floor(4.4) == 4
class A(object):
def __trunc__(self):
return 2
def __ceil__(self):
return 3
def __floor__(self):
return 4
assert math.trunc(A()) == 2
assert math.ceil(A()) == 3
assert math.floor(A()) == 4
class A(object):
def __trunc__(self):
return 2.2
def __ceil__(self):
return 3.3
def __floor__(self):
return 4.4
assert math.trunc(A()) == 2.2
assert math.ceil(A()) == 3.3
assert math.floor(A()) == 4.4
class A(object):
def __trunc__(self):
return 'trunc'
def __ceil__(self):
return 'ceil'
def __floor__(self):
return 'floor'
assert math.trunc(A()) == 'trunc'
assert math.ceil(A()) == 'ceil'
assert math.floor(A()) == 'floor'
with assertRaises(TypeError):
math.trunc(object())
with assertRaises(TypeError):
math.ceil(object())
with assertRaises(TypeError):
math.floor(object())