-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathops.py
More file actions
135 lines (123 loc) · 2.25 KB
/
ops.py
File metadata and controls
135 lines (123 loc) · 2.25 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Copyright 2018 The go-python Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
_2 = 2
_10 = 10
_11 = 11
_100 = 100
a=[0,1,2,3,4]
doc="Unary Ops"
assert +_2 == 2
assert -_2 == -2
assert not _2 is False
assert ~_2 == -3
doc="Binary Ops"
assert _2**_10 == 1024
assert _2*_10 == 20
assert _10//_2 == 5
assert _11//_2 == 5
assert _10/_2 == 5.0
assert _11/_2 == 5.5
assert _10 % _2 == 0
assert _11 % _2 == 1
assert _10 + _2 == 12
assert _10 - _2 == 8
assert a[1] == 1
assert a[4] == 4
assert _2 << _10 == 2048
assert _100 >> 2 == 25
assert _10 & _2 == 2
assert _100 | _2 == 102
assert _10 ^ _2 == 8
doc="Inplace Ops"
a = _2
a **= _10
assert a == 1024
a = _2
a *= _10
assert a == 20
a = _10
a //= _2
assert a == 5
a = _11
a //= _2
assert a == 5
a = _10
a /= _2
assert a == 5.0
a = _11
a /= _2
assert a == 5.5
a = _10
a %= _2
assert a == 0
a = _11
a %= _2
assert a == 1
a = _10
a += _2
assert a == 12
a = _10
a -= _2
assert a == 8
a = _2
a <<= _10
assert a == 2048
a = _100
a >>= 2
assert a == 25
a = _10
a &= _2
assert a == 2
a = _100
a |= _2
assert a == 102
a = _10
a ^= _2
assert a == 8
doc="Comparison"
assert _2 < _10
assert _2 <= _10
assert _2 <= _2
assert _2 == _2
assert _2 != _10
assert _10 > _2
assert _10 >= _2
assert _2 >= _2
assert _2 in (1,2,3)
assert _100 not in (1,2,3)
assert True is True
assert True is not False
# FIXME EXC_MATCH
doc="Multiple comparison"
assert _2 < _10 < _11 < _100
assert not (_10 < _2 < _11 < _100)
assert _100 > _11 > _10 > _2
doc="logical"
t = True
f = False
assert (f and f) == False
assert (f and t) == False
assert (t and f) == False
assert (t and t) == True
assert (f and f and f) == False
assert (f and f and t) == False
assert (f and t and f) == False
assert (f and t and t) == False
assert (t and f and f) == False
assert (t and f and t) == False
assert (t and t and f) == False
assert (t and t and t) == True
assert (f or f) == False
assert (f or t) == True
assert (t or f) == True
assert (t or t) == True
assert (f or f or f) == False
assert (f or f or t) == True
assert (f or t or f) == True
assert (f or t or t) == True
assert (t or f or f) == True
assert (t or f or t) == True
assert (t or t or f) == True
assert (t or t or t) == True
doc="finished"