Commit 37b0f335 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

objset: Add frozenset tests, skippable if frozenset not available.

parent 43d4a6fa
# basic sets
try:
frozenset
except NameError:
print("SKIP")
import sys
sys.exit()
s = frozenset({1})
print(s)
s = frozenset({3, 4, 3, 1})
print(sorted(s))
try:
frozenset
except NameError:
print("SKIP")
import sys
sys.exit()
s = frozenset({1, 2, 3, 4})
try:
print(s.add(5))
except AttributeError:
print("AttributeError")
try:
frozenset
except NameError:
print("SKIP")
import sys
sys.exit()
sets = [
frozenset(), frozenset({1}), frozenset({1, 2}), frozenset({1, 2, 3}), frozenset({2, 3}),
frozenset({2, 3, 5}), frozenset({5}), frozenset({7})
]
for s in sets:
for t in sets:
print(sorted(s), '|', sorted(t), '=', sorted(s | t))
print(sorted(s), '^', sorted(t), '=', sorted(s ^ t))
print(sorted(s), '&', sorted(t), '=', sorted(s & t))
print(sorted(s), '-', sorted(t), '=', sorted(s - t))
u = s.copy()
u |= t
print(sorted(s), "|=", sorted(t), '-->', sorted(u))
u = s.copy()
u ^= t
print(sorted(s), "^=", sorted(t), '-->', sorted(u))
u = s.copy()
u &= t
print(sorted(s), "&=", sorted(t), "-->", sorted(u))
u = s.copy()
u -= t
print(sorted(s), "-=", sorted(t), "-->", sorted(u))
print(sorted(s), '==', sorted(t), '=', s == t)
print(sorted(s), '!=', sorted(t), '=', s != t)
print(sorted(s), '>', sorted(t), '=', s > t)
print(sorted(s), '>=', sorted(t), '=', s >= t)
print(sorted(s), '<', sorted(t), '=', s < t)
print(sorted(s), '<=', sorted(t), '=', s <= t)
try:
frozenset
except NameError:
print("SKIP")
import sys
sys.exit()
s = frozenset({1, 2, 3, 4})
t = s.copy()
print(type(t))
for i in s, t:
print(sorted(i))
try:
frozenset
except NameError:
print("SKIP")
import sys
sys.exit()
l = [1, 2, 3, 4]
s = frozenset(l)
outs = [s.difference(),
s.difference(frozenset({1})),
s.difference(frozenset({1}), [1, 2]),
s.difference(frozenset({1}), {1, 2}, {2, 3})]
for out in outs:
print(type(out), sorted(out))
s = frozenset(l)
try:
print(s.difference_update({1}))
except AttributeError:
print("AttributeError")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment