forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperator_comparison.py
More file actions
89 lines (70 loc) · 2.08 KB
/
operator_comparison.py
File metadata and controls
89 lines (70 loc) · 2.08 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
81
82
83
84
85
86
87
88
89
from testutils import assert_raises
assert 1 < 2
assert 1 < 2 < 3
assert 5 == 5 == 5
assert (5 == 5) == True
assert 5 == 5 != 4 == 4 > 3 > 2 < 3 <= 3 != 0 == 0
assert not 1 > 2
assert not 5 == 5 == True
assert not 5 == 5 != 5 == 5
assert not 1 < 2 < 3 > 4
assert not 1 < 2 > 3 < 4
assert not 1 > 2 < 3 < 4
def test_type_error(x, y):
assert_raises(TypeError, lambda: x < y)
assert_raises(TypeError, lambda: x <= y)
assert_raises(TypeError, lambda: x > y)
assert_raises(TypeError, lambda: x >= y)
test_type_error([], 0)
test_type_error((), 0)
# 10**308 cannot be represented exactly in f64, thus it is not equal to 1e308 float
assert not (10**308 == 1e308)
# but the 1e308 float can be converted to big int and then it still should be equal to itself
assert int(1e308) == 1e308
# and the equalities should be the same when operands switch sides
assert not (1e308 == 10**308)
assert 1e308 == int(1e308)
# floats that cannot be converted to big ints shouldn’t crash the vm
import math
assert not (10**500 == math.inf)
assert not (math.inf == 10**500)
assert not (10**500 == math.nan)
assert not (math.nan == 10**500)
# comparisons
# floats with worse than integer precision
assert 2.0**54 > 2**54 - 1
assert 2.0**54 < 2**54 + 1
assert 2.0**54 >= 2**54 - 1
assert 2.0**54 <= 2**54 + 1
assert 2.0**54 == 2**54
assert not 2.0**54 == 2**54 + 1
# inverse operands
assert 2**54 - 1 < 2.0**54
assert 2**54 + 1 > 2.0**54
assert 2**54 - 1 <= 2.0**54
assert 2**54 + 1 >= 2.0**54
assert 2**54 == 2.0**54
assert not 2**54 + 1 == 2.0**54
assert not 2.0**54 < 2**54 - 1
assert not 2.0**54 > 2**54 + 1
# sub-int numbers
assert 1.3 > 1
assert 1.3 >= 1
assert 2.5 > 2
assert 2.5 >= 2
assert -0.3 < 0
assert -0.3 <= 0
# int out of float range comparisons
assert 10**500 > 2.0**54
assert -(10**500) < -0.12
# infinity and NaN comparisons
assert math.inf > 10**500
assert math.inf >= 10**500
assert not math.inf < 10**500
assert -math.inf < -10 * 500
assert -math.inf <= -10 * 500
assert not -math.inf > -10 * 500
assert not math.nan > 123
assert not math.nan < 123
assert not math.nan >= 123
assert not math.nan <= 123