micropython/tests/basics/set_binop.py

31 lines
845 B
Python
Raw Normal View History

2014-01-12 23:09:10 +00:00
def r(s):
l = list(s)
l.sort()
2014-01-12 23:37:45 +00:00
return l
sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}]
for s in sets:
for t in sets:
print(s, '|', t, '=', r(s | t))
print(s, '^', t, '=', r(s ^ t))
print(s, '&', t, '=', r(s & t))
print(s, '-', t, '=', r(s - t))
u = s.copy()
u |= t
print(s, "|=", t, '-->', r(u))
u = s.copy()
u ^= t
print(s, "^=", t, '-->', r(u))
u = s.copy()
u &= t
print(s, "&=", t, "-->", r(u))
u = s.copy()
u -= t
print(s, "-=", t, "-->", r(u))
2014-01-12 23:09:10 +00:00
2014-01-12 23:37:45 +00:00
print(s, '==', t, '=', s == t)
print(s, '!=', t, '=', s != t)
print(s, '>', t, '=', s > t)
print(s, '>=', t, '=', s >= t)
print(s, '<', t, '=', s < t)
print(s, '<=', t, '=', s <= t)